Package org.apache.blur.manager.writer

Examples of org.apache.blur.manager.writer.BlurIndex


      throw new BException(e.getMessage(), e);
    }
    return ForkJoin.execute(_executor, blurIndexes.entrySet(), new ParallelCall<Entry<String, BlurIndex>, Long>() {
      @Override
      public Long call(Entry<String, BlurIndex> input) throws Exception {
        BlurIndex index = input.getValue();
        IndexSearcherClosable searcher = index.getIndexReader();
        try {
          return recordFrequency(searcher.getIndexReader(), columnFamily, columnName, value);
        } finally {
          // this will allow for closing of index
          searcher.close();
View Full Code Here


    }
    return ForkJoin.execute(_executor, blurIndexes.entrySet(),
        new ParallelCall<Entry<String, BlurIndex>, List<String>>() {
          @Override
          public List<String> call(Entry<String, BlurIndex> input) throws Exception {
            BlurIndex index = input.getValue();
            IndexSearcherClosable searcher = index.getIndexReader();
            try {
              return terms(searcher.getIndexReader(), columnFamily, columnName, startWith, size);
            } finally {
              // this will allow for closing of index
              searcher.close();
View Full Code Here

    for (int i = 0; i < mutations.size(); i++) {
      RowMutation mutation = mutations.get(i);
      if (mutation.waitToBeVisible) {
        waitToBeVisible = true;
      }
      BlurIndex blurIndex = indexes.get(shard);
      if (blurIndex == null) {
        throw new BException("Shard [" + shard + "] in table [" + table + "] is not being served by this server.");
      }

      boolean waitVisiblity = false;
      if (i + 1 == mutations.size()) {
        waitVisiblity = waitToBeVisible;
      }
      RowMutationType type = mutation.rowMutationType;
      switch (type) {
      case REPLACE_ROW:
        Row row = MutationHelper.getRowFromMutations(mutation.rowId, mutation.recordMutations);
        blurIndex.replaceRow(waitVisiblity, mutation.wal, updateMetrics(row));
        break;
      case UPDATE_ROW:
        doUpdateRowMutation(mutation, blurIndex);
        break;
      case DELETE_ROW:
        blurIndex.deleteRow(waitVisiblity, mutation.wal, mutation.rowId);
        break;
      default:
        throw new RuntimeException("Not supported [" + type + "]");
      }
    }
View Full Code Here

  private void doMutate(RowMutation mutation) throws BlurException, IOException {
    String table = mutation.table;
    Map<String, BlurIndex> indexes = _indexServer.getIndexes(table);
    MutationHelper.validateMutation(mutation);
    String shard = MutationHelper.getShardName(table, mutation.rowId, getNumberOfShards(table), _blurPartitioner);
    BlurIndex blurIndex = indexes.get(shard);
    if (blurIndex == null) {
      throw new BException("Shard [" + shard + "] in table [" + table + "] is not being served by this server.");
    }

    RowMutationType type = mutation.rowMutationType;
    switch (type) {
    case REPLACE_ROW:
      Row row = MutationHelper.getRowFromMutations(mutation.rowId, mutation.recordMutations);
      blurIndex.replaceRow(mutation.waitToBeVisible, mutation.wal, updateMetrics(row));
      break;
    case UPDATE_ROW:
      doUpdateRowMutation(mutation, blurIndex);
      break;
    case DELETE_ROW:
      blurIndex.deleteRow(mutation.waitToBeVisible, mutation.wal, mutation.rowId);
      break;
    default:
      throw new RuntimeException("Not supported [" + type + "]");
    }
  }
View Full Code Here

          Map<String, BlurIndex> indexes = oldIndexesThatNeedToBeClosed.get(table);
          if (indexes == null) {
            continue;
          }
          for (String shard : indexes.keySet()) {
            BlurIndex index = indexes.get(shard);
            if (index == null) {
              continue;
            }
            close(index, table, shard);
            closed = true;
          }
        }
        for (String table : _indexes.keySet()) {
          Map<String, BlurIndex> shardMap = _indexes.get(table);
          if (shardMap != null) {
            Set<String> shards = new HashSet<String>(shardMap.keySet());
            Set<String> shardsToServe = getShardsToServe(table);
            shards.removeAll(shardsToServe);
            if (!shards.isEmpty()) {
              LOG.info("Need to close indexes for table [{0}] indexes [{1}]", table, shards);
            }
            for (String shard : shards) {
              LOG.info("Closing index for table [{0}] shard [{1}]", table, shard);
              BlurIndex index = shardMap.remove(shard);
              close(index, table, shard);
              closed = true;
            }
          }
        }
View Full Code Here

  }

  private void closeAllIndexes() {
    for (Entry<String, Map<String, BlurIndex>> tableToShards : _indexes.entrySet()) {
      for (Entry<String, BlurIndex> shard : tableToShards.getValue().entrySet()) {
        BlurIndex index = shard.getValue();
        try {
          index.close();
          LOG.info("Closed [{0}] [{1}] [{2}]", tableToShards.getKey(), shard.getKey(), index);
        } catch (IOException e) {
          LOG.info("Error during closing of [{0}] [{1}] [{2}]", tableToShards.getKey(), shard.getKey(), index);
        }
      }
View Full Code Here

      dir = _blockCacheDirectoryFactory.newDirectory(table + "_" + shard, directory, blockCacheFileTypes);
    } else {
      dir = directory;
    }

    BlurIndex index;
    if (_clusterStatus.isReadOnly(true, _cluster, table)) {
      BlurIndexReader reader = new BlurIndexReader(shardContext, dir, _refresher, _indexCloser);
      index = reader;
    } else {
      BlurNRTIndex writer = new BlurNRTIndex(shardContext, _mergeScheduler, _closer, dir, _gc, _searchExecutor);
View Full Code Here

  private synchronized Map<String, BlurIndex> openMissingShards(final String table, Set<String> shardsToServe,
      final Map<String, BlurIndex> tableIndexes) {
    Map<String, Future<BlurIndex>> opening = new HashMap<String, Future<BlurIndex>>();
    for (String s : shardsToServe) {
      final String shard = s;
      BlurIndex blurIndex = tableIndexes.get(shard);
      if (blurIndex == null) {
        _pauseWarmup.incrementAndGet();
        LOG.info("Opening missing shard [{0}] from table [{1}]", shard, table);
        Future<BlurIndex> submit = _openerService.submit(new Callable<BlurIndex>() {
          @Override
          public BlurIndex call() throws Exception {
            _shardStateManager.opening(table, shard);
            try {
              BlurIndex openShard = openShard(table, shard);
              _shardStateManager.open(table, shard);
              return openShard;
            } catch (Exception e) {
              _shardStateManager.openingError(table, shard);
              throw e;
            } catch (Throwable t) {
              _shardStateManager.openingError(table, shard);
              throw new RuntimeException(t);
            } finally {
              _pauseWarmup.decrementAndGet();
            }
          }
        });
        opening.put(shard, submit);
      }
    }

    for (Entry<String, Future<BlurIndex>> entry : opening.entrySet()) {
      String shard = entry.getKey();
      Future<BlurIndex> future = entry.getValue();
      try {
        BlurIndex blurIndex = future.get();
        tableIndexes.put(shard, blurIndex);
      } catch (Exception e) {
        e.printStackTrace();
        LOG.error("Unknown error while opening shard [{0}] for table [{1}].", e.getCause(), shard, table);
      }
    }

    Map<String, BlurIndex> result = new HashMap<String, BlurIndex>();
    for (String shard : shardsToServe) {
      BlurIndex blurIndex = tableIndexes.get(shard);
      if (blurIndex == null) {
        LOG.error("Missing shard [{0}] for table [{1}].", shard, table);
      } else {
        result.put(shard, blurIndex);
      }
View Full Code Here

    }
  }

  public void fetchRow(String table, Selector selector, FetchResult fetchResult) throws BlurException {
    validSelector(selector);
    BlurIndex index;
    String shard;
    try {
      if (selector.getLocationId() == null) {
        // Not looking up by location id so we should resetSearchers.
        ShardServerContext.resetSearchers();
        populateSelector(table, selector);
      }
      String locationId = selector.getLocationId();
      if (locationId.equals(NOT_FOUND)) {
        fetchResult.setDeleted(false);
        fetchResult.setExists(false);
        return;
      }
      shard = getShard(locationId);
      Map<String, BlurIndex> blurIndexes = _indexServer.getIndexes(table);
      if (blurIndexes == null) {
        LOG.error("Table [{0}] not found", table);
        // @TODO probably should make a enum for not found on this server so the
        // controller knows to try another server.
        throw new BException("Table [" + table + "] not found");
      }
      index = blurIndexes.get(shard);
      if (index == null) {
        LOG.error("Shard [{0}] not found in table [{1}]", shard, table);
        // @TODO probably should make a enum for not found on this server so the
        // controller knows to try another server.
        throw new BException("Shard [" + shard + "] not found in table [" + table + "]");
      }
    } catch (BlurException e) {
      throw e;
    } catch (Exception e) {
      LOG.error("Unknown error while trying to get the correct index reader for selector [{0}].", e, selector);
      throw new BException(e.getMessage(), e);
    }
    IndexSearcherClosable searcher = null;
    TimerContext timerContext = _fetchTimer.time();
    boolean usedCache = true;
    try {
      ShardServerContext shardServerContext = ShardServerContext.getShardServerContext();
      if (shardServerContext != null) {
        searcher = shardServerContext.getIndexSearcherClosable(table, shard);
      }
      if (searcher == null) {
        searcher = index.getIndexReader();
        usedCache = false;
      }

      TableContext tableContext = getTableContext(table);
      FieldManager fieldManager = tableContext.getFieldManager();
View Full Code Here

  private void populateSelector(String table, Selector selector) throws IOException, BlurException {
    String rowId = selector.rowId;
    String recordId = selector.recordId;
    String shardName = MutationHelper.getShardName(table, rowId, getNumberOfShards(table), _blurPartitioner);
    Map<String, BlurIndex> indexes = _indexServer.getIndexes(table);
    BlurIndex blurIndex = indexes.get(shardName);
    if (blurIndex == null) {
      throw new BException("Shard [" + shardName + "] is not being servered by this shardserver.");
    }
    IndexSearcherClosable searcher = blurIndex.getIndexReader();
    try {
      BooleanQuery query = new BooleanQuery();
      if (selector.recordOnly) {
        query.add(new TermQuery(new Term(RECORD_ID, recordId)), Occur.MUST);
        query.add(new TermQuery(new Term(ROW_ID, rowId)), Occur.MUST);
View Full Code Here

TOP

Related Classes of org.apache.blur.manager.writer.BlurIndex

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.