Search in sources :

Example 6 with Nullable

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;
}
Also used : IOException(java.io.IOException) BytesStreamOutput(org.elasticsearch.common.io.stream.BytesStreamOutput) BytesRef(org.apache.lucene.util.BytesRef) Nullable(org.elasticsearch.common.Nullable)

Example 7 with Nullable

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);
    }
}
Also used : StreamInput(org.elasticsearch.common.io.stream.StreamInput) ArrayList(java.util.ArrayList) IOException(java.io.IOException) BytesRef(org.apache.lucene.util.BytesRef) Nullable(org.elasticsearch.common.Nullable)

Example 8 with Nullable

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;
}
Also used : DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) EvaluatingNormalizer(io.crate.analyze.EvaluatingNormalizer) Symbol(io.crate.analyze.symbol.Symbol) ArrayList(java.util.ArrayList) NodeStatsContext(io.crate.operation.reference.sys.node.NodeStatsContext) Nullable(org.elasticsearch.common.Nullable)

Example 9 with Nullable

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;
}
Also used : IndexSettings(org.elasticsearch.index.IndexSettings) Supplier(java.util.function.Supplier) ParameterizedMessage(org.apache.logging.log4j.message.ParameterizedMessage) IndexNotFoundException(org.elasticsearch.index.IndexNotFoundException) LockObtainFailedException(org.apache.lucene.store.LockObtainFailedException) IOException(java.io.IOException) ElasticsearchException(org.elasticsearch.ElasticsearchException) ShardLockObtainFailedException(org.elasticsearch.env.ShardLockObtainFailedException) IllegalIndexShardStateException(org.elasticsearch.index.shard.IllegalIndexShardStateException) ResourceAlreadyExistsException(org.elasticsearch.ResourceAlreadyExistsException) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData) Nullable(org.elasticsearch.common.Nullable)

Example 10 with Nullable

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;
}
Also used : TranslogConfig(org.elasticsearch.index.translog.TranslogConfig) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) ElasticsearchException(org.elasticsearch.ElasticsearchException) Matchers.containsString(org.hamcrest.Matchers.containsString) AlreadyClosedException(org.apache.lucene.store.AlreadyClosedException) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) BrokenBarrierException(java.util.concurrent.BrokenBarrierException) ElasticsearchException(org.elasticsearch.ElasticsearchException) CodecService(org.elasticsearch.index.codec.CodecService) Nullable(org.elasticsearch.common.Nullable) LiveIndexWriterConfig(org.apache.lucene.index.LiveIndexWriterConfig) IndexWriterConfig(org.apache.lucene.index.IndexWriterConfig)

Aggregations

Nullable (org.elasticsearch.common.Nullable)17 IOException (java.io.IOException)9 ArrayList (java.util.ArrayList)4 ElasticsearchException (org.elasticsearch.ElasticsearchException)4 IndexSettings (org.elasticsearch.index.IndexSettings)4 IndexWriterConfig (org.apache.lucene.index.IndexWriterConfig)3 Directory (org.apache.lucene.store.Directory)3 IndexMetaData (org.elasticsearch.cluster.metadata.IndexMetaData)3 CodecService (org.elasticsearch.index.codec.CodecService)3 TranslogConfig (org.elasticsearch.index.translog.TranslogConfig)3 Configuration (com.microsoft.windowsazure.Configuration)2 ManagementConfiguration (com.microsoft.windowsazure.management.configuration.ManagementConfiguration)2 HashSet (java.util.HashSet)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 LiveIndexWriterConfig (org.apache.lucene.index.LiveIndexWriterConfig)2 AlreadyClosedException (org.apache.lucene.store.AlreadyClosedException)2 BytesRef (org.apache.lucene.util.BytesRef)2 BytesStreamOutput (org.elasticsearch.common.io.stream.BytesStreamOutput)2 Engine (org.elasticsearch.index.engine.Engine)2 DirectoryService (org.elasticsearch.index.store.DirectoryService)2