/** * Queue up an indexOperationMessage for multi region execution * * @param indexOperationMessage */ public void queueIndexOperationMessage(final IndexOperationMessage indexOperationMessage) { // don't try to produce something with nothing if (indexOperationMessage == null || indexOperationMessage.isEmpty()) { return; } final String jsonValue = ObjectJsonSerializer.INSTANCE.toString(indexOperationMessage); final UUID newMessageId = UUIDGenerator.newTimeUUID(); final int expirationTimeInSeconds = (int) TimeUnit.MILLISECONDS.toSeconds(indexProcessorFig.getIndexMessageTtl()); // write to the map in ES esMapPersistence.putString(newMessageId.toString(), jsonValue, expirationTimeInSeconds); // now queue up the index message final ElasticsearchIndexEvent elasticsearchIndexEvent = new ElasticsearchIndexEvent(queueFig.getPrimaryRegion(), newMessageId); // send to the topic so all regions index the batch offerTopic(elasticsearchIndexEvent); }
private void handleIndexOperation(final ElasticsearchIndexEvent elasticsearchIndexEvent) throws IndexDocNotFoundException { Preconditions.checkNotNull(elasticsearchIndexEvent, "elasticsearchIndexEvent cannot be null"); final UUID messageId = elasticsearchIndexEvent.getIndexBatchId(); Preconditions.checkNotNull(messageId, "messageId must not be null"); final String message = esMapPersistence.getString(messageId.toString()); final IndexOperationMessage indexOperationMessage; if (message == null) { // provide some time back pressure before performing a quorum read if (queueFig.getQuorumFallback() && System.currentTimeMillis() > elasticsearchIndexEvent.getCreationTime() + queueFig.getLocalQuorumTimeout()) { if (logger.isDebugEnabled()) { logger.debug("ES batch with id {} not found, reading with strong consistency", messageId); } final String highConsistency = esMapPersistence.getStringHighConsistency(messageId.toString()); if (highConsistency == null) { throw new RuntimeException( "ES batch with id " + messageId + " not found when reading with strong consistency"); } indexOperationMessage = ObjectJsonSerializer.INSTANCE.fromString(highConsistency, IndexOperationMessage.class); } else { throw new IndexDocNotFoundException(elasticsearchIndexEvent.getIndexBatchId()); } } else { indexOperationMessage = ObjectJsonSerializer.INSTANCE.fromString(message, IndexOperationMessage.class); } // don't let this continue if there's nothing to index if (indexOperationMessage == null || indexOperationMessage.isEmpty()) { throw new RuntimeException( "IndexOperationMessage cannot be null or empty after retrieving from map persistence"); } // always do a check to ensure the indexes are initialized for the index requests initializeEntityIndexes(indexOperationMessage); // send it to to be indexed indexProducer.put(indexOperationMessage).toBlocking().last(); }