This is an automated email from the ASF dual-hosted git repository.
nehapawar pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pinot.git
The following commit(s) were added to refs/heads/master by this push:
new 89529ff Use ConcurrentHashMap in SegmentDirectoryLoaderRegistry and
add test (#7967)
89529ff is described below
commit 89529ff05ae38859321c0a36418941324a8e5b3b
Author: Neha Pawar <[email protected]>
AuthorDate: Thu Dec 30 10:56:37 2021 -0800
Use ConcurrentHashMap in SegmentDirectoryLoaderRegistry and add test (#7967)
---
.../loader/SegmentDirectoryLoaderRegistryTest.java | 57 ++++++++++++++++++++++
.../spi/loader/SegmentDirectoryLoaderRegistry.java | 17 ++++---
2 files changed, 67 insertions(+), 7 deletions(-)
diff --git
a/pinot-segment-local/src/test/java/org/apache/pinot/segment/local/segment/loader/SegmentDirectoryLoaderRegistryTest.java
b/pinot-segment-local/src/test/java/org/apache/pinot/segment/local/segment/loader/SegmentDirectoryLoaderRegistryTest.java
new file mode 100644
index 0000000..3112223
--- /dev/null
+++
b/pinot-segment-local/src/test/java/org/apache/pinot/segment/local/segment/loader/SegmentDirectoryLoaderRegistryTest.java
@@ -0,0 +1,57 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pinot.segment.local.segment.loader;
+
+import java.net.URI;
+import org.apache.pinot.segment.local.loader.DefaultSegmentDirectoryLoader;
+import org.apache.pinot.segment.spi.loader.SegmentDirectoryLoader;
+import org.apache.pinot.segment.spi.loader.SegmentDirectoryLoaderContext;
+import org.apache.pinot.segment.spi.loader.SegmentDirectoryLoaderRegistry;
+import org.apache.pinot.segment.spi.store.SegmentDirectory;
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+
+public class SegmentDirectoryLoaderRegistryTest {
+
+ @Test
+ public void testSegmentDirectoryLoaderRegistry() {
+ SegmentDirectoryLoader defaultSegmentDirectoryLoader =
+ SegmentDirectoryLoaderRegistry.getDefaultSegmentDirectoryLoader();
+
Assert.assertEquals(defaultSegmentDirectoryLoader.getClass().getSimpleName(),
+ DefaultSegmentDirectoryLoader.class.getSimpleName());
+ defaultSegmentDirectoryLoader =
SegmentDirectoryLoaderRegistry.getSegmentDirectoryLoader("default");
+
Assert.assertEquals(defaultSegmentDirectoryLoader.getClass().getSimpleName(),
+ DefaultSegmentDirectoryLoader.class.getSimpleName());
+
+
Assert.assertNull(SegmentDirectoryLoaderRegistry.getSegmentDirectoryLoader("custom"));
+ SegmentDirectoryLoaderRegistry.setSegmentDirectoryLoader("custom", new
CustomSegmentDirectoryLoader());
+
Assert.assertEquals(SegmentDirectoryLoaderRegistry.getSegmentDirectoryLoader("custom").getClass().getSimpleName(),
+ CustomSegmentDirectoryLoader.class.getSimpleName());
+ }
+
+ private static class CustomSegmentDirectoryLoader implements
SegmentDirectoryLoader {
+
+ @Override
+ public SegmentDirectory load(URI indexDir, SegmentDirectoryLoaderContext
segmentDirectoryLoaderContext)
+ throws Exception {
+ return null;
+ }
+ }
+}
diff --git
a/pinot-segment-spi/src/main/java/org/apache/pinot/segment/spi/loader/SegmentDirectoryLoaderRegistry.java
b/pinot-segment-spi/src/main/java/org/apache/pinot/segment/spi/loader/SegmentDirectoryLoaderRegistry.java
index cd235b5..407ef32 100644
---
a/pinot-segment-spi/src/main/java/org/apache/pinot/segment/spi/loader/SegmentDirectoryLoaderRegistry.java
+++
b/pinot-segment-spi/src/main/java/org/apache/pinot/segment/spi/loader/SegmentDirectoryLoaderRegistry.java
@@ -18,9 +18,9 @@
*/
package org.apache.pinot.segment.spi.loader;
-import java.util.HashMap;
import java.util.Map;
import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
import org.reflections.Reflections;
import org.reflections.scanners.ResourcesScanner;
import org.reflections.scanners.SubTypesScanner;
@@ -37,11 +37,15 @@ import org.slf4j.LoggerFactory;
*/
public class SegmentDirectoryLoaderRegistry {
private static final Logger LOGGER =
LoggerFactory.getLogger(SegmentDirectoryLoaderRegistry.class);
-
public static final String DEFAULT_SEGMENT_DIRECTORY_LOADER_NAME = "default";
- private static final Map<String, SegmentDirectoryLoader>
SEGMENT_DIRECTORY_LOADER_MAP = new HashMap<>();
+ private static final Map<String, SegmentDirectoryLoader>
SEGMENT_DIRECTORY_LOADER_MAP = new ConcurrentHashMap<>();
+
+ private SegmentDirectoryLoaderRegistry() {
+ }
static {
+ long startTime = System.currentTimeMillis();
+
Reflections reflections = new Reflections(
new
ConfigurationBuilder().setUrls(ClasspathHelper.forPackage("org.apache.pinot.segment"))
.filterInputsBy(new FilterBuilder.Include(".*\\.loader\\..*"))
@@ -66,11 +70,10 @@ public class SegmentDirectoryLoaderRegistry {
}
}
});
- LOGGER.info("Initialized {} with {} segmentDirectoryLoaders: {}",
SegmentDirectoryLoaderRegistry.class.getName(),
- SEGMENT_DIRECTORY_LOADER_MAP.size(),
SEGMENT_DIRECTORY_LOADER_MAP.keySet());
- }
- private SegmentDirectoryLoaderRegistry() {
+ LOGGER.info("Initialized SegmentDirectoryLoaderRegistry with {}
segmentDirectoryLoaders: {} in {} ms",
+ SEGMENT_DIRECTORY_LOADER_MAP.size(),
SEGMENT_DIRECTORY_LOADER_MAP.keySet(),
+ (System.currentTimeMillis() - startTime));
}
/**
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]