use of org.elasticsearch.common.Nullable in project crate by crate.
the class PartitionName method encodeIdent.
@Nullable
public static String encodeIdent(Collection<? extends BytesRef> values) {
if (values.size() == 0) {
return null;
}
BytesStreamOutput streamOutput = new BytesStreamOutput(estimateSize(values));
try {
streamOutput.writeVInt(values.size());
for (BytesRef value : values) {
StringType.INSTANCE.streamer().writeValueTo(streamOutput, value);
}
} catch (IOException e) {
throw Throwables.propagate(e);
}
String identBase32 = BASE32.encodeAsString(streamOutput.bytes().toBytes()).toLowerCase(Locale.ROOT);
// decode doesn't need padding, remove it
int idx = identBase32.indexOf('=');
if (idx > -1) {
return identBase32.substring(0, idx);
}
return identBase32;
}
use of org.elasticsearch.common.Nullable in project crate by crate.
the class PartitionName method decodeIdent.
/**
* decodes an encoded ident into it's values
*/
@Nullable
public static List<BytesRef> decodeIdent(@Nullable String ident) {
if (ident == null) {
return ImmutableList.of();
}
byte[] inputBytes = BASE32.decode(ident.toUpperCase(Locale.ROOT));
try (StreamInput in = StreamInput.wrap(inputBytes)) {
int size = in.readVInt();
List<BytesRef> values = new ArrayList<>(size);
for (int i = 0; i < size; i++) {
values.add(StringType.INSTANCE.streamer().readValueFrom(in));
}
return values;
} catch (IOException e) {
throw new IllegalArgumentException(String.format(Locale.ENGLISH, "Invalid partition ident: %s", ident), e);
}
}
use of org.elasticsearch.common.Nullable in project crate by crate.
the class NodeStatsCollectSource method nodeIds.
@Nullable
static Collection<DiscoveryNode> nodeIds(WhereClause whereClause, Collection<DiscoveryNode> nodes, Functions functions) {
if (!whereClause.hasQuery()) {
return nodes;
}
LocalSysColReferenceResolver localSysColReferenceResolver = new LocalSysColReferenceResolver(ImmutableList.of(SysNodesTableInfo.Columns.NAME, SysNodesTableInfo.Columns.ID));
EvaluatingNormalizer normalizer = new EvaluatingNormalizer(functions, RowGranularity.DOC, ReplaceMode.COPY, localSysColReferenceResolver, null);
List<DiscoveryNode> newNodes = new ArrayList<>();
for (DiscoveryNode node : nodes) {
String nodeId = node.getId();
for (RowCollectExpression<NodeStatsContext, ?> expression : localSysColReferenceResolver.expressions()) {
expression.setNextRow(new NodeStatsContext(nodeId, node.name()));
}
Symbol normalized = normalizer.normalize(whereClause.query(), null);
if (normalized.equals(whereClause.query())) {
// No local available sys nodes columns in where clause
return nodes;
}
if (WhereClause.canMatch(normalized)) {
newNodes.add(node);
}
}
return newNodes;
}
use of org.elasticsearch.common.Nullable in project elasticsearch by elastic.
the class IndicesService method verifyIndexIsDeleted.
/**
* Verify that the contents on disk for the given index is deleted; if not, delete the contents.
* This method assumes that an index is already deleted in the cluster state and/or explicitly
* through index tombstones.
* @param index {@code Index} to make sure its deleted from disk
* @param clusterState {@code ClusterState} to ensure the index is not part of it
* @return IndexMetaData for the index loaded from disk
*/
@Override
@Nullable
public IndexMetaData verifyIndexIsDeleted(final Index index, final ClusterState clusterState) {
// this method should only be called when we know the index (name + uuid) is not part of the cluster state
if (clusterState.metaData().index(index) != null) {
throw new IllegalStateException("Cannot delete index [" + index + "], it is still part of the cluster state.");
}
if (nodeEnv.hasNodeFile() && FileSystemUtils.exists(nodeEnv.indexPaths(index))) {
final IndexMetaData metaData;
try {
metaData = metaStateService.loadIndexState(index);
} catch (Exception e) {
logger.warn((Supplier<?>) () -> new ParameterizedMessage("[{}] failed to load state file from a stale deleted index, folders will be left on disk", index), e);
return null;
}
final IndexSettings indexSettings = buildIndexSettings(metaData);
try {
deleteIndexStoreIfDeletionAllowed("stale deleted index", index, indexSettings, ALWAYS_TRUE);
} catch (Exception e) {
// we just warn about the exception here because if deleteIndexStoreIfDeletionAllowed
// throws an exception, it gets added to the list of pending deletes to be tried again
logger.warn((Supplier<?>) () -> new ParameterizedMessage("[{}] failed to delete index on disk", metaData.getIndex()), e);
}
return metaData;
}
return null;
}
use of org.elasticsearch.common.Nullable in project elasticsearch by elastic.
the class InternalEngineTests method config.
public EngineConfig config(IndexSettings indexSettings, Store store, Path translogPath, MergePolicy mergePolicy, SnapshotDeletionPolicy deletionPolicy, long maxUnsafeAutoIdTimestamp, ReferenceManager.RefreshListener refreshListener) {
IndexWriterConfig iwc = newIndexWriterConfig();
TranslogConfig translogConfig = new TranslogConfig(shardId, translogPath, indexSettings, BigArrays.NON_RECYCLING_INSTANCE);
final EngineConfig.OpenMode openMode;
try {
if (Lucene.indexExists(store.directory()) == false) {
openMode = EngineConfig.OpenMode.CREATE_INDEX_AND_TRANSLOG;
} else {
openMode = EngineConfig.OpenMode.OPEN_INDEX_AND_TRANSLOG;
}
} catch (IOException e) {
throw new ElasticsearchException("can't find index?", e);
}
Engine.EventListener listener = new Engine.EventListener() {
@Override
public void onFailedEngine(String reason, @Nullable Exception e) {
// we don't need to notify anybody in this test
}
};
EngineConfig config = new EngineConfig(openMode, shardId, threadPool, indexSettings, null, store, deletionPolicy, mergePolicy, iwc.getAnalyzer(), iwc.getSimilarity(), new CodecService(null, logger), listener, new TranslogHandler(xContentRegistry(), shardId.getIndexName(), logger), IndexSearcher.getDefaultQueryCache(), IndexSearcher.getDefaultQueryCachingPolicy(), translogConfig, TimeValue.timeValueMinutes(5), refreshListener, maxUnsafeAutoIdTimestamp);
return config;
}
Aggregations