public String[] listAll() throws IOException {
   String[] primaryFiles = primaryDir.listAll();
   String[] secondaryFiles = secondaryDir.listAll();
   String[] files = new String[primaryFiles.length + secondaryFiles.length];
   System.arraycopy(primaryFiles, 0, files, 0, primaryFiles.length);
   System.arraycopy(secondaryFiles, 0, files, primaryFiles.length, secondaryFiles.length);
   return files;
 }
Beispiel #2
0
 static Map<String, String> readChecksums(Directory[] dirs, Map<String, String> defaultValue)
     throws IOException {
   long lastFound = -1;
   Directory lastDir = null;
   for (Directory dir : dirs) {
     for (String name : dir.listAll()) {
       if (!isChecksum(name)) {
         continue;
       }
       long current = Long.parseLong(name.substring(CHECKSUMS_PREFIX.length()));
       if (current > lastFound) {
         lastFound = current;
         lastDir = dir;
       }
     }
   }
   if (lastFound == -1) {
     return defaultValue;
   }
   IndexInput indexInput = lastDir.openInput(CHECKSUMS_PREFIX + lastFound, IOContext.READONCE);
   try {
     indexInput.readInt(); // version
     return indexInput.readStringStringMap();
   } catch (Exception e) {
     // failed to load checksums, ignore and return an empty map
     return defaultValue;
   } finally {
     indexInput.close();
   }
 }
Beispiel #3
0
 public void assertDeleteContent(Store store, DirectoryService service) throws IOException {
   store.deleteContent();
   assertThat(
       Arrays.toString(store.directory().listAll()),
       store.directory().listAll().length,
       equalTo(0));
   assertThat(store.stats().sizeInBytes(), equalTo(0l));
   for (Directory dir : service.build()) {
     assertThat(dir.listAll().length, equalTo(0));
   }
 }
Beispiel #4
0
 StoreDirectory(Distributor distributor) throws IOException {
   this.distributor = distributor;
   synchronized (mutex) {
     MapBuilder<String, StoreFileMetaData> builder = MapBuilder.newMapBuilder();
     Map<String, String> checksums =
         readChecksums(distributor.all(), new HashMap<String, String>());
     for (Directory delegate : distributor.all()) {
       for (String file : delegate.listAll()) {
         String checksum = checksums.get(file);
         builder.put(
             file, new StoreFileMetaData(file, delegate.fileLength(file), checksum, delegate));
       }
     }
     filesMetadata = builder.immutableMap();
     files = filesMetadata.keySet().toArray(new String[filesMetadata.size()]);
   }
 }
 public static void checkIndex(ESLogger logger, Store store, ShardId shardId) {
   if (store.tryIncRef()) {
     logger.info("start check index");
     try {
       Directory dir = store.directory();
       if (!Lucene.indexExists(dir)) {
         return;
       }
       if (IndexWriter.isLocked(dir)) {
         ESTestCase.checkIndexFailed = true;
         throw new IllegalStateException("IndexWriter is still open on shard " + shardId);
       }
       try (CheckIndex checkIndex = new CheckIndex(dir)) {
         BytesStreamOutput os = new BytesStreamOutput();
         PrintStream out = new PrintStream(os, false, StandardCharsets.UTF_8.name());
         checkIndex.setInfoStream(out);
         out.flush();
         CheckIndex.Status status = checkIndex.checkIndex();
         if (!status.clean) {
           ESTestCase.checkIndexFailed = true;
           logger.warn(
               "check index [failure] index files={}\n{}",
               Arrays.toString(dir.listAll()),
               new String(os.bytes().toBytes(), StandardCharsets.UTF_8));
           throw new IOException("index check failure");
         } else {
           if (logger.isDebugEnabled()) {
             logger.debug(
                 "check index [success]\n{}",
                 new String(os.bytes().toBytes(), StandardCharsets.UTF_8));
           }
         }
       }
     } catch (Exception e) {
       logger.warn("failed to check index", e);
     } finally {
       logger.info("end check index");
       store.decRef();
     }
   }
 }
 @Override
 public String[] listAll() throws IOException {
   return in.listAll();
 }