use of org.elasticsearch.ElasticSearchException in project elasticsearch-indexing-proxy by codelibs.
the class RequestSender method process.
private void process(final long filePosition) {
if (logger.isDebugEnabled()) {
logger.debug("RequestSender(" + index + ") processes " + filePosition);
}
path = dataPath.resolve(String.format(dataFileFormat, filePosition) + IndexingProxyPlugin.DATA_EXTENTION);
if (FileAccessUtils.existsFile(path)) {
logger.info("[Sender][{}] Indexing: {}", index, path.toAbsolutePath());
requestPosition = 0;
try {
processRequests(AccessController.doPrivileged((PrivilegedAction<IndexingProxyStreamInput>) () -> {
try {
return new IndexingProxyStreamInput(Files.newInputStream(path), namedWriteableRegistry);
} catch (final IOException e) {
throw new ElasticsearchException("Failed to read " + path.toAbsolutePath(), e);
}
}));
// continue
} catch (final Exception e) {
retryWithError("Failed to access " + path.toAbsolutePath(), e);
// retry
}
} else {
if (logger.isDebugEnabled()) {
logger.debug("{} does not exist.", path.toAbsolutePath());
}
long next = getNextValue(filePosition);
for (long i = 0; i < senderLookupFiles; i++) {
if (FileAccessUtils.existsFile(dataPath.resolve(String.format(dataFileFormat, next) + IndexingProxyPlugin.DATA_EXTENTION))) {
logger.warn("[Sender][" + index + "] file_id " + filePosition + " is skipped. Moving to file_id " + next);
processNext(next);
return;
// continue
}
next = getNextValue(next);
}
threadPool.schedule(senderInterval, Names.GENERIC, this);
// retry
}
}
use of org.elasticsearch.ElasticSearchException in project bw-calendar-engine by Bedework.
the class BwIndexEsImpl method newIndex.
@Override
public String newIndex(final String name) throws CalFacadeException {
try {
final String newName = name + newIndexSuffix();
targetIndex = newName;
final IndicesAdminClient idx = getAdminIdx();
final CreateIndexRequestBuilder cirb = idx.prepareCreate(newName);
final File f = new File(idxpars.getIndexerConfig());
final byte[] sbBytes = Streams.copyToByteArray(f);
cirb.setSource(sbBytes);
final CreateIndexRequest cir = cirb.request();
final ActionFuture<CreateIndexResponse> af = idx.create(cir);
/*resp = */
af.actionGet();
index(new UpdateInfo());
info("Index created: change token set to " + currentChangeToken());
return newName;
} catch (final ElasticsearchException ese) {
// Failed somehow
error(ese);
return null;
} catch (final CalFacadeException cfe) {
throw cfe;
} catch (final Throwable t) {
error(t);
throw new CalFacadeException(t);
}
}
use of org.elasticsearch.ElasticSearchException in project bw-calendar-engine by Bedework.
the class BwIndexEsImpl method setAlias.
@Override
public int setAlias(final String index, final String alias) throws CalFacadeException {
// IndicesAliasesResponse resp = null;
try {
/* Other is the alias name - index is the index we were just indexing into
*/
final IndicesAdminClient idx = getAdminIdx();
final GetAliasesRequestBuilder igarb = idx.prepareGetAliases(alias);
final ActionFuture<GetAliasesResponse> getAliasesAf = idx.getAliases(igarb.request());
final GetAliasesResponse garesp = getAliasesAf.actionGet();
final ImmutableOpenMap<String, List<AliasMetaData>> aliasesmeta = garesp.getAliases();
final IndicesAliasesRequestBuilder iarb = idx.prepareAliases();
final Iterator<String> it = aliasesmeta.keysIt();
while (it.hasNext()) {
final String indexName = it.next();
for (final AliasMetaData amd : aliasesmeta.get(indexName)) {
if (amd.getAlias().equals(alias)) {
iarb.removeAlias(indexName, alias);
}
}
}
iarb.addAlias(index, alias);
final ActionFuture<IndicesAliasesResponse> af = idx.aliases(iarb.request());
/*resp = */
af.actionGet();
return 0;
} catch (final ElasticsearchException ese) {
// Failed somehow
error(ese);
return -1;
} catch (final CalFacadeException cfe) {
throw cfe;
} catch (final Throwable t) {
throw new CalFacadeException(t);
}
}
use of org.elasticsearch.ElasticSearchException in project bw-calendar-engine by Bedework.
the class BwIndexEsImpl method currentChangeToken.
@Override
public String currentChangeToken() throws CalFacadeException {
UpdateInfo ui;
try {
final GetRequestBuilder grb = getClient().prepareGet(targetIndex, docTypeUpdateTracker, updateTrackerId).setFields("count", "_timestamp");
final GetResponse gr = grb.execute().actionGet();
if (!gr.isExists()) {
return null;
}
final EntityBuilder er = getEntityBuilder(gr.getFields());
ui = er.makeUpdateInfo();
} catch (final ElasticsearchException ese) {
warn("Exception getting UpdateInfo: " + ese.getLocalizedMessage());
ui = new UpdateInfo();
}
synchronized (updateInfo) {
UpdateInfo tui = updateInfo.get(targetIndex);
if ((tui != null) && (tui.getCount() >= (0111111111 - 1000))) {
// Reset before we overflow
tui = null;
}
if ((tui == null) || (!tui.getCount().equals(ui.getCount()))) {
updateInfo.put(targetIndex, ui);
} else {
ui = tui;
}
}
return ui.getChangeToken();
}
use of org.elasticsearch.ElasticSearchException in project bw-calendar-engine by Bedework.
the class BwIndexEsImpl method markTransaction.
@Override
public void markTransaction() throws CalFacadeException {
final UpdateInfo ui = updateInfo.get(targetIndex);
if ((ui != null) && !ui.isUpdate()) {
return;
}
try {
final UpdateRequestBuilder urb = getClient().prepareUpdate(targetIndex, docTypeUpdateTracker, updateTrackerId).setRetryOnConflict(20).setRefresh(true);
urb.setScript("ctx._source.count += 1", ScriptService.ScriptType.INLINE);
final UpdateResponse ur = urb.execute().actionGet();
} catch (final ElasticsearchException ese) {
warn("Exception updating UpdateInfo: " + ese.getLocalizedMessage());
index(new UpdateInfo());
}
}
Aggregations