コード例 #1
0
  private boolean removeIndexUpdater(String indexName) {
    indexerRegistry.unregister(indexName);

    IndexUpdaterHandle handle = indexUpdaters.get(indexName);

    if (handle == null) {
      return true;
    }

    try {
      handle.stop();
      indexUpdaters.remove(indexName);
      log.info("Stopped indexer updater for index " + indexName);
      return true;
    } catch (Throwable t) {
      log.fatal("Failed to stop an IndexUpdater that should be stopped.", t);
      return false;
    }
  }
コード例 #2
0
  @PreDestroy
  public void stop() {
    eventWorker.stop();
    eventWorkerThread.interrupt();
    try {
      Logs.logThreadJoin(eventWorkerThread);
      eventWorkerThread.join();
    } catch (InterruptedException e) {
      log.info("Interrupted while joining eventWorkerThread.");
    }

    for (IndexUpdaterHandle handle : indexUpdaters.values()) {
      try {
        handle.stop();
      } catch (InterruptedException e) {
        // Continue the stop procedure
      }
    }

    connectionManager.shutdown();
  }
コード例 #3
0
  private void addIndexUpdater(IndexDefinition index) {
    IndexUpdaterHandle handle = null;
    try {
      IndexerConf indexerConf =
          IndexerConfBuilder.build(new ByteArrayInputStream(index.getConfiguration()), repository);

      ShardSelector shardSelector;
      if (index.getShardingConfiguration() == null) {
        shardSelector = DefaultShardSelectorBuilder.createDefaultSelector(index.getSolrShards());
      } else {
        shardSelector = JsonShardSelectorBuilder.build(index.getShardingConfiguration());
      }

      checkShardUsage(index.getName(), index.getSolrShards().keySet(), shardSelector.getShards());

      SolrShardManager solrShardMgr =
          new SolrShardManagerImpl(
              index.getName(),
              index.getSolrShards(),
              shardSelector,
              httpClient,
              solrClientConfig,
              true);
      IndexLocker indexLocker = new IndexLocker(zk, settings.getEnableLocking());
      IndexerMetrics indexerMetrics = new IndexerMetrics(index.getName());

      // create a deref map in case the indexer configuration contains deref fields
      DerefMap derefMap =
          indexerConf.containsDerefExpressions()
              ? DerefMapHbaseImpl.create(index.getName(), hbaseConf, repository.getIdGenerator())
              : null;

      // create and register the indexer
      Indexer indexer =
          new Indexer(
              index.getName(),
              indexerConf,
              repository,
              solrShardMgr,
              indexLocker,
              indexerMetrics,
              derefMap);
      indexerRegistry.register(indexer);

      IndexUpdaterMetrics updaterMetrics = new IndexUpdaterMetrics(index.getName());
      IndexUpdater indexUpdater =
          new IndexUpdater(
              indexer,
              repository,
              indexLocker,
              rowLog,
              updaterMetrics,
              derefMap,
              index.getQueueSubscriptionId());

      List<RemoteListenerHandler> listenerHandlers = new ArrayList<RemoteListenerHandler>();

      for (int i = 0; i < settings.getListenersPerIndex(); i++) {
        RemoteListenerHandler handler =
            new RemoteListenerHandler(
                rowLog, index.getQueueSubscriptionId(), indexUpdater, rowLogConfMgr, hostName);
        listenerHandlers.add(handler);
      }

      handle =
          new IndexUpdaterHandle(
              index, listenerHandlers, solrShardMgr, indexerMetrics, updaterMetrics);
      handle.start();

      indexUpdaters.put(index.getName(), handle);

      log.info("Started index updater for index " + index.getName());
    } catch (Throwable t) {
      if (t instanceof InterruptedException) {
        Thread.currentThread().interrupt();
      }

      log.error("Problem starting index updater for index " + index.getName(), t);

      if (handle != null) {
        // stop any listeners that might have been started
        try {
          handle.stop();
        } catch (Throwable t2) {
          if (t instanceof InterruptedException) {
            Thread.currentThread().interrupt();
          }
          log.error(
              "Problem stopping listeners for failed-to-start index updater for index '"
                  + index.getName()
                  + "'",
              t2);
        }
      }
    }
  }