@Override public int estimatedSizeInBytes() { return (id().length() + type().length()) * 2 + source().length() + 12; }
private Engine.IndexResult index(Engine engine, Engine.Index index) throws IOException { active.set(true); final Engine.IndexResult result; index = indexingOperationListeners.preIndex(shardId, index); try { if (logger.isTraceEnabled()) { // don't use index.source().utf8ToString() here source might not be valid UTF-8 logger.trace("index [{}][{}] (seq# [{}])", index.type(), index.id(), index.seqNo()); } result = engine.index(index); } catch (Exception e) { indexingOperationListeners.postIndex(shardId, index, e); throw e; } indexingOperationListeners.postIndex(shardId, index, result); return result; }
/** * Asserts that the doc in the index operation really doesn't exist */ private boolean assertDocDoesNotExist(final Index index, final boolean allowDeleted) throws IOException { // NOTE this uses direct access to the version map since we are in the assertion code where we maintain a secondary // map in the version map such that we don't need to refresh if we are unsafe; final VersionValue versionValue = versionMap.getVersionForAssert(index.uid().bytes()); if (versionValue != null) { if (versionValue.isDelete() == false || allowDeleted == false) { throw new AssertionError("doc [" + index.type() + "][" + index.id() + "] exists in version map (version " + versionValue + ")"); } } else { try (Searcher searcher = acquireSearcher("assert doc doesn't exist", SearcherScope.INTERNAL)) { final long docsWithId = searcher.searcher().count(new TermQuery(index.uid())); if (docsWithId > 0) { throw new AssertionError("doc [" + index.type() + "][" + index.id() + "] exists [" + docsWithId + "] times in index"); } } } return true; }
@Override public void postIndexUnderLock(Engine.Index index) { // add the query under a doc lock if (BatchPercolatorService.TYPE_NAME.equals(index.type())) { addPercolateQuery(index.id(), index.source()); } }
@Override public int estimatedSizeInBytes() { return (id().length() + type().length()) * 2 + source().length() + 12; }
public Index(Engine.Index index, Engine.IndexResult indexResult) { this.id = index.id(); this.type = index.type(); this.source = index.source(); this.routing = index.routing(); this.parent = index.parent(); this.seqNo = indexResult.getSeqNo(); this.primaryTerm = index.primaryTerm(); this.version = indexResult.getVersion(); this.versionType = index.versionType(); this.autoGeneratedIdTimestamp = index.getAutoGeneratedIdTimestamp(); }
@Override public void postIndex(ShardId shardId, Engine.Index index, Engine.IndexResult result) { ChangeEvent change=new ChangeEvent( shardId.getIndex().getName(), index.type(), index.id(), new DateTime(), result.isCreated() ? ChangeEvent.Operation.CREATE : ChangeEvent.Operation.INDEX, result.getVersion(), index.source() ); addChange(change); }
public Index(Engine.Index index) { this.id = index.id(); this.type = index.type(); this.source = index.source(); this.routing = index.routing(); this.parent = index.parent(); this.version = index.version(); this.timestamp = index.timestamp(); this.ttl = index.ttl(); this.versionType = index.versionType(); }
@Override public Engine.Index preIndex(Engine.Index index) { // validate the query here, before we index if (BatchPercolatorService.TYPE_NAME.equals(index.type())) { parsePercolatorDocument(index.id(), index.source()); } return index; }
public Index(Engine.Index index, Engine.IndexResult indexResult) { this.id = index.id(); this.type = index.type(); this.source = index.source(); this.routing = index.routing(); this.parent = index.parent(); this.version = indexResult.getVersion(); this.timestamp = index.timestamp(); this.ttl = index.ttl(); this.versionType = index.versionType(); this.autoGeneratedIdTimestamp = index.getAutoGeneratedIdTimestamp(); }
@Override public Engine.Index preIndex(ShardId shardId, Engine.Index operation) { if (operation.origin().isRecovery() == false) { totalStats.indexCurrent.inc(); typeStats(operation.type()).indexCurrent.inc(); } return operation; }
@Override public Engine.Index preIndex(ShardId shardId, Engine.Index operation) { if (operation.origin().isRecovery() == false) { totalStats.indexCurrent.inc(); typeStats(operation.type()).indexCurrent.inc(); } return operation; }
@Override public Engine.Index preIndex(ShardId shardId, Engine.Index operation) { if (!operation.origin().isRecovery()) { totalStats.indexCurrent.inc(); typeStats(operation.type()).indexCurrent.inc(); } return operation; }
final VersionConflictEngineException e = new VersionConflictEngineException(shardId, index.type(), index.id(), index.getIfSeqNo(), index.getIfPrimaryTerm(), SequenceNumbers.UNASSIGNED_SEQ_NO, 0); plan = IndexingStrategy.skipDueToVersionConflict(e, currentNotFoundOrDeleted, currentVersion, getPrimaryTerm()); versionValue.seqNo != index.getIfSeqNo() || versionValue.term != index.getIfPrimaryTerm() )) { final VersionConflictEngineException e = new VersionConflictEngineException(shardId, index.type(), index.id(), index.getIfSeqNo(), index.getIfPrimaryTerm(), versionValue.seqNo, versionValue.term); plan = IndexingStrategy.skipDueToVersionConflict(e, currentNotFoundOrDeleted, currentVersion, getPrimaryTerm());
@Override public void postIndex(ShardId shardId, Engine.Index index, Engine.IndexResult result) { switch (result.getResultType()) { case SUCCESS: if (index.origin().isRecovery() == false) { long took = result.getTook(); totalStats.indexMetric.inc(took); totalStats.indexCurrent.dec(); StatsHolder typeStats = typeStats(index.type()); typeStats.indexMetric.inc(took); typeStats.indexCurrent.dec(); } break; case FAILURE: postIndex(shardId, index, result.getFailure()); break; default: throw new IllegalArgumentException("unknown result type: " + result.getResultType()); } }
@Override public Engine.Index preIndex(ShardId shardId, Engine.Index operation) { if (operation.origin().isRecovery() == false) { totalStats.indexCurrent.inc(); typeStats(operation.type()).indexCurrent.inc(); } return operation; }
public Index(Engine.Index index, Engine.IndexResult indexResult) { this.id = index.id(); this.type = index.type(); this.source = index.source(); this.routing = index.routing(); this.parent = index.parent(); this.seqNo = indexResult.getSeqNo(); this.primaryTerm = index.primaryTerm(); this.version = indexResult.getVersion(); this.versionType = index.versionType(); this.autoGeneratedIdTimestamp = index.getAutoGeneratedIdTimestamp(); }