Ejemplo n.º 1
0
 private void maybeRefreshEngine() {
   if (indexSettings.getRefreshInterval().millis() > 0) {
     for (IndexShard shard : this.shards.values()) {
       switch (shard.state()) {
         case CREATED:
         case RECOVERING:
         case CLOSED:
           continue;
         case POST_RECOVERY:
         case STARTED:
         case RELOCATED:
           try {
             if (shard.isRefreshNeeded()) {
               shard.refresh("schedule");
             }
           } catch (EngineClosedException | AlreadyClosedException ex) {
             // fine - continue;
           }
           continue;
         default:
           throw new IllegalStateException("unknown state: " + shard.state());
       }
     }
   }
 }
 protected final void processAfter(
     boolean refresh, IndexShard indexShard, Translog.Location location) {
   if (refresh) {
     try {
       indexShard.refresh("refresh_flag_index");
     } catch (Throwable e) {
       // ignore
     }
   }
   if (indexShard.getTranslogDurability() == Translog.Durabilty.REQUEST && location != null) {
     indexShard.sync(location);
   }
   indexShard.maybeFlush();
 }
 private Set<Uid> getShardDocUIDs(final IndexShard shard) throws IOException {
   shard.refresh("get_uids");
   try (Engine.Searcher searcher = shard.acquireSearcher("test")) {
     Set<Uid> ids = new HashSet<>();
     for (LeafReaderContext leafContext : searcher.reader().leaves()) {
       LeafReader reader = leafContext.reader();
       Bits liveDocs = reader.getLiveDocs();
       for (int i = 0; i < reader.maxDoc(); i++) {
         if (liveDocs == null || liveDocs.get(i)) {
           Document uuid = reader.document(i, Collections.singleton(UidFieldMapper.NAME));
           ids.add(Uid.createUid(uuid.get(UidFieldMapper.NAME)));
         }
       }
     }
     return ids;
   }
 }
 public synchronized void refresh(String source) {
   for (IndexShard shard : this) {
     shard.refresh(source);
   }
 }