コード例 #1
0
 public void testFailLoadShardPathIndexUUIDMissmatch() throws IOException {
   try (final NodeEnvironment env = newNodeEnvironment(Settings.builder().build())) {
     Settings.Builder builder =
         Settings.builder()
             .put(IndexMetaData.SETTING_INDEX_UUID, "foobar")
             .put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT);
     Settings settings = builder.build();
     ShardId shardId = new ShardId("foo", "foobar", 0);
     Path[] paths = env.availableShardPaths(shardId);
     Path path = randomFrom(paths);
     int id = randomIntBetween(1, 10);
     ShardStateMetaData.FORMAT.write(
         new ShardStateMetaData(id, true, "0xDEADBEEF", AllocationId.newInitializing()), path);
     Exception e =
         expectThrows(
             IllegalStateException.class,
             () ->
                 ShardPath.loadShardPath(
                     logger,
                     env,
                     shardId,
                     IndexSettingsModule.newIndexSettings(shardId.getIndex(), settings)));
     assertThat(e.getMessage(), containsString("expected: foobar on shard path"));
   }
 }
コード例 #2
0
 public void testLoadShardPath() throws IOException {
   try (final NodeEnvironment env = newNodeEnvironment(Settings.builder().build())) {
     Settings.Builder builder =
         Settings.builder()
             .put(IndexMetaData.SETTING_INDEX_UUID, "0xDEADBEEF")
             .put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT);
     Settings settings = builder.build();
     ShardId shardId = new ShardId("foo", "0xDEADBEEF", 0);
     Path[] paths = env.availableShardPaths(shardId);
     Path path = randomFrom(paths);
     ShardStateMetaData.FORMAT.write(
         new ShardStateMetaData(2, true, "0xDEADBEEF", AllocationId.newInitializing()), path);
     ShardPath shardPath =
         ShardPath.loadShardPath(
             logger,
             env,
             shardId,
             IndexSettingsModule.newIndexSettings(shardId.getIndex(), settings));
     assertEquals(path, shardPath.getDataPath());
     assertEquals("0xDEADBEEF", shardPath.getShardId().getIndex().getUUID());
     assertEquals("foo", shardPath.getShardId().getIndexName());
     assertEquals(path.resolve("translog"), shardPath.resolveTranslog());
     assertEquals(path.resolve("index"), shardPath.resolveIndex());
   }
 }
コード例 #3
0
 public void testFailLoadShardPathOnMultiState() throws IOException {
   try (final NodeEnvironment env = newNodeEnvironment(Settings.builder().build())) {
     final String indexUUID = "0xDEADBEEF";
     Settings.Builder builder =
         Settings.builder()
             .put(IndexMetaData.SETTING_INDEX_UUID, indexUUID)
             .put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT);
     Settings settings = builder.build();
     ShardId shardId = new ShardId("foo", indexUUID, 0);
     Path[] paths = env.availableShardPaths(shardId);
     assumeTrue("This test tests multi data.path but we only got one", paths.length > 1);
     int id = randomIntBetween(1, 10);
     ShardStateMetaData.FORMAT.write(
         new ShardStateMetaData(id, true, indexUUID, AllocationId.newInitializing()), paths);
     Exception e =
         expectThrows(
             IllegalStateException.class,
             () ->
                 ShardPath.loadShardPath(
                     logger,
                     env,
                     shardId,
                     IndexSettingsModule.newIndexSettings(shardId.getIndex(), settings)));
     assertThat(e.getMessage(), containsString("more than one shard state found"));
   }
 }
コード例 #4
0
 public void testGetRootPaths() throws IOException {
   boolean useCustomDataPath = randomBoolean();
   final Settings indexSettings;
   final Settings nodeSettings;
   final String indexUUID = "0xDEADBEEF";
   Settings.Builder indexSettingsBuilder =
       Settings.builder()
           .put(IndexMetaData.SETTING_INDEX_UUID, indexUUID)
           .put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT);
   final Path customPath;
   if (useCustomDataPath) {
     final Path path = createTempDir();
     final boolean includeNodeId = randomBoolean();
     indexSettings = indexSettingsBuilder.put(IndexMetaData.SETTING_DATA_PATH, "custom").build();
     nodeSettings =
         Settings.builder()
             .put(
                 Environment.PATH_SHARED_DATA_SETTING.getKey(),
                 path.toAbsolutePath().toAbsolutePath())
             .put(NodeEnvironment.ADD_NODE_LOCK_ID_TO_CUSTOM_PATH.getKey(), includeNodeId)
             .build();
     if (includeNodeId) {
       customPath = path.resolve("custom").resolve("0");
     } else {
       customPath = path.resolve("custom");
     }
   } else {
     customPath = null;
     indexSettings = indexSettingsBuilder.build();
     nodeSettings = Settings.EMPTY;
   }
   try (final NodeEnvironment env = newNodeEnvironment(nodeSettings)) {
     ShardId shardId = new ShardId("foo", indexUUID, 0);
     Path[] paths = env.availableShardPaths(shardId);
     Path path = randomFrom(paths);
     ShardStateMetaData.FORMAT.write(
         new ShardStateMetaData(2, true, indexUUID, AllocationId.newInitializing()), path);
     ShardPath shardPath =
         ShardPath.loadShardPath(
             logger,
             env,
             shardId,
             IndexSettingsModule.newIndexSettings(
                 shardId.getIndex(), indexSettings, nodeSettings));
     boolean found = false;
     for (Path p : env.nodeDataPaths()) {
       if (p.equals(shardPath.getRootStatePath())) {
         found = true;
         break;
       }
     }
     assertTrue(
         "root state paths must be a node path but wasn't: " + shardPath.getRootStatePath(),
         found);
     found = false;
     if (useCustomDataPath) {
       assertNotEquals(shardPath.getRootDataPath(), shardPath.getRootStatePath());
       assertEquals(customPath, shardPath.getRootDataPath());
     } else {
       assertNull(customPath);
       for (Path p : env.nodeDataPaths()) {
         if (p.equals(shardPath.getRootDataPath())) {
           found = true;
           break;
         }
       }
       assertTrue(
           "root state paths must be a node path but wasn't: " + shardPath.getRootDataPath(),
           found);
     }
   }
 }