org.elasticsearch.index.Index Java Examples

The following examples show how to use org.elasticsearch.index.Index. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TransportUpdateSettingsAction.java    From crate with Apache License 2.0 6 votes vote down vote up
@Override
protected void masterOperation(final UpdateSettingsRequest request, final ClusterState state, final ActionListener<AcknowledgedResponse> listener) {
    final Index[] concreteIndices = indexNameExpressionResolver.concreteIndices(state, request);
    UpdateSettingsClusterStateUpdateRequest clusterStateUpdateRequest = new UpdateSettingsClusterStateUpdateRequest()
            .indices(concreteIndices)
            .settings(request.settings())
            .setPreserveExisting(request.isPreserveExisting())
            .ackTimeout(request.timeout())
            .masterNodeTimeout(request.masterNodeTimeout());

    updateSettingsService.updateSettings(clusterStateUpdateRequest, new ActionListener<ClusterStateUpdateResponse>() {
        @Override
        public void onResponse(ClusterStateUpdateResponse response) {
            listener.onResponse(new AcknowledgedResponse(response.isAcknowledged()));
        }

        @Override
        public void onFailure(Exception t) {
            logger.debug(() -> new ParameterizedMessage("failed to update settings on indices [{}]", (Object) concreteIndices), t);
            listener.onFailure(t);
        }
    });
}
 
Example #2
Source File: SwapRelationsOperation.java    From crate with Apache License 2.0 6 votes vote down vote up
private void removeOccurrences(ClusterState state,
                               ClusterBlocks.Builder blocksBuilder,
                               RoutingTable.Builder routingBuilder,
                               MetaData.Builder updatedMetaData,
                               RelationName name) {
    String aliasOrIndexName = name.indexNameOrAlias();
    String templateName = PartitionName.templateName(name.schema(), name.name());
    for (Index index : indexNameResolver.concreteIndices(
        state, IndicesOptions.LENIENT_EXPAND_OPEN, aliasOrIndexName)) {

        String indexName = index.getName();
        routingBuilder.remove(indexName);
        updatedMetaData.remove(indexName);
        blocksBuilder.removeIndexBlocks(indexName);
    }
    updatedMetaData.removeTemplate(templateName);
}
 
Example #3
Source File: HunspellTokenFilterFactory.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
@Inject
public HunspellTokenFilterFactory(Index index, IndexSettingsService indexSettingsService, @Assisted String name, @Assisted Settings settings, HunspellService hunspellService)  {
    super(index, indexSettingsService.getSettings(), name, settings);

    String locale = settings.get("locale", settings.get("language", settings.get("lang", null)));
    if (locale == null) {
        throw new IllegalArgumentException("missing [locale | language | lang] configuration for hunspell token filter");
    }

    dictionary = hunspellService.getDictionary(locale);
    if (dictionary == null) {
        throw new IllegalArgumentException(String.format(Locale.ROOT, "Unknown hunspell dictionary for locale [%s]", locale));
    }

    dedup = settings.getAsBoolean("dedup", true);
    longestOnly = settings.getAsBoolean("longest_only", false);
}
 
Example #4
Source File: TransportShardDeleteActionTest.java    From crate with Apache License 2.0 6 votes vote down vote up
@Before
public void prepare() throws Exception {
    indexUUID = UUIDs.randomBase64UUID();
    IndicesService indicesService = mock(IndicesService.class);
    IndexService indexService = mock(IndexService.class);
    when(indicesService.indexServiceSafe(new Index(TABLE_IDENT.indexNameOrAlias(), indexUUID))).thenReturn(indexService);
    indexShard = mock(IndexShard.class);
    when(indexService.getShard(0)).thenReturn(indexShard);


    transportShardDeleteAction = new TransportShardDeleteAction(
        MockTransportService.createNewService(
            Settings.EMPTY, Version.CURRENT, THREAD_POOL, clusterService.getClusterSettings()),
        mock(IndexNameExpressionResolver.class),
        mock(ClusterService.class),
        indicesService,
        mock(ThreadPool.class),
        mock(ShardStateAction.class),
        mock(SchemaUpdateClient.class)
    );
}
 
Example #5
Source File: NodeIndicesStats.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
private Map<Index, CommonStats> createStatsByIndex() {
    Map<Index, CommonStats> statsMap = Maps.newHashMap();
    for (Map.Entry<Index, List<IndexShardStats>> entry : statsByShard.entrySet()) {
        if (!statsMap.containsKey(entry.getKey())) {
            statsMap.put(entry.getKey(), new CommonStats());
        }

        for (IndexShardStats indexShardStats : entry.getValue()) {
            for (ShardStats shardStats : indexShardStats.getShards()) {
                statsMap.get(entry.getKey()).add(shardStats.getStats());
            }
        }
    }

    return statsMap;
}
 
Example #6
Source File: CodecService.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
private CodecService(Index index, Settings indexSettings, MapperService mapperService) {
    super(index, indexSettings);
    this.mapperService = mapperService;
    MapBuilder<String, Codec> codecs = MapBuilder.<String, Codec>newMapBuilder();
    if (mapperService == null) {
        codecs.put(DEFAULT_CODEC, new Lucene54Codec());
        codecs.put(BEST_COMPRESSION_CODEC, new Lucene54Codec(Mode.BEST_COMPRESSION));
    } else {
        codecs.put(DEFAULT_CODEC, 
                new PerFieldMappingPostingFormatCodec(Mode.BEST_SPEED, mapperService, logger));
        codecs.put(BEST_COMPRESSION_CODEC, 
                new PerFieldMappingPostingFormatCodec(Mode.BEST_COMPRESSION, mapperService, logger));
    }
    codecs.put(LUCENE_DEFAULT_CODEC, Codec.getDefault());
    for (String codec : Codec.availableCodecs()) {
        codecs.put(codec, Codec.forName(codec));
    }
    this.codecs = codecs.immutableMap();
}
 
Example #7
Source File: IcuCollationAnalyzerTests.java    From elasticsearch-plugin-bundle with GNU Affero General Public License v3.0 6 votes vote down vote up
public void testNormalization() throws Exception {
    Settings settings = Settings.builder()
            .put("index.analysis.analyzer.myAnalyzer.type", "icu_collation")
            .put("index.analysis.analyzer.myAnalyzer.language", "tr")
            .put("index.analysis.analyzer.myAnalyzer.strength", "primary")
            .put("index.analysis.analyzer.myAnalyzer.decomposition", "canonical")
            .build();
    ESTestCase.TestAnalysis analysis = ESTestCase.createTestAnalysis(new Index("test", "_na_"),
            settings,
            new BundlePlugin(Settings.EMPTY));
    Analyzer analyzer = analysis.indexAnalyzers.get("myAnalyzer");
    TokenStream tsUpper = analyzer.tokenStream(null, "I W\u0049\u0307LL USE TURKİSH CASING");
    BytesRef b1 = bytesFromTokenStream(tsUpper);
    TokenStream tsLower = analyzer.tokenStream(null, "ı will use turkish casıng");
    BytesRef b2 = bytesFromTokenStream(tsLower);
    assertTrue(compare(b1.bytes, b2.bytes) == 0);
}
 
Example #8
Source File: IndexStore.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
@Inject
public IndexStore(Index index, IndexSettingsService settingsService, IndicesStore indicesStore) {
    super(index, settingsService.getSettings());
    Settings indexSettings = settingsService.getSettings();
    this.indicesStore = indicesStore;

    this.rateLimitingType = indexSettings.get(INDEX_STORE_THROTTLE_TYPE, "none");
    if (rateLimitingType.equalsIgnoreCase("node")) {
        nodeRateLimiting = true;
    } else {
        nodeRateLimiting = false;
        rateLimiting.setType(rateLimitingType);
    }
    this.rateLimitingThrottle = indexSettings.getAsBytesSize(INDEX_STORE_THROTTLE_MAX_BYTES_PER_SEC, new ByteSizeValue(0));
    rateLimiting.setMaxRate(rateLimitingThrottle);

    logger.debug("using index.store.throttle.type [{}], with index.store.throttle.max_bytes_per_sec [{}]", rateLimitingType, rateLimitingThrottle);
    this.settingsService = settingsService;
    this.settingsService.addListener(applySettings);
}
 
Example #9
Source File: NodeEnvironment.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
/**
 * Tries to find all allocated shards for the given index
 * on the current node. NOTE: This methods is prone to race-conditions on the filesystem layer since it might not
 * see directories created concurrently or while it's traversing.
 * @param index the index to filter shards
 * @return a set of shard IDs
 * @throws IOException if an IOException occurs
 */
public Set<ShardId> findAllShardIds(final Index index) throws IOException {
    assert index != null;
    if (nodePaths == null || locks == null) {
        throw new IllegalStateException("node is not configured to store local location");
    }
    assert assertEnvIsLocked();
    final Set<ShardId> shardIds = Sets.newHashSet();
    String indexName = index.name();
    for (final NodePath nodePath : nodePaths) {
        Path location = nodePath.indicesPath;
        if (Files.isDirectory(location)) {
            try (DirectoryStream<Path> indexStream = Files.newDirectoryStream(location)) {
                for (Path indexPath : indexStream) {
                    if (indexName.equals(indexPath.getFileName().toString())) {
                        shardIds.addAll(findAllShardsForIndex(indexPath));
                    }
                }
            }
        }
    }
    return shardIds;
}
 
Example #10
Source File: MetaStateService.java    From crate with Apache License 2.0 5 votes vote down vote up
/**
 * Loads the full state, which includes both the global state and all the indices meta data. <br>
 * When loading, manifest file is consulted (represented by {@link Manifest} class), to load proper generations. <br>
 * If there is no manifest file on disk, this method fallbacks to BWC mode, where latest generation of global and indices
 * metadata is loaded. Please note that currently there is no way to distinguish between manifest file being removed and manifest
 * file was not yet created. It means that this method always fallbacks to BWC mode, if there is no manifest file.
 *
 * @return tuple of {@link Manifest} and {@link MetaData} with global metadata and indices metadata. If there is no state on disk,
 * meta state with globalGeneration -1 and empty meta data is returned.
 * @throws IOException if some IOException when loading files occurs or there is no metadata referenced by manifest file.
 */
Tuple<Manifest, MetaData> loadFullState() throws IOException {
    final Manifest manifest = MANIFEST_FORMAT.loadLatestState(LOGGER, namedXContentRegistry, nodeEnv.nodeDataPaths());
    if (manifest == null) {
        return loadFullStateBWC();
    }

    final MetaData.Builder metaDataBuilder;
    if (manifest.isGlobalGenerationMissing()) {
        metaDataBuilder = MetaData.builder();
    } else {
        final MetaData globalMetaData = META_DATA_FORMAT.loadGeneration(LOGGER, namedXContentRegistry, manifest.getGlobalGeneration(),
                nodeEnv.nodeDataPaths());
        if (globalMetaData != null) {
            metaDataBuilder = MetaData.builder(globalMetaData);
        } else {
            throw new IOException("failed to find global metadata [generation: " + manifest.getGlobalGeneration() + "]");
        }
    }

    for (Map.Entry<Index, Long> entry : manifest.getIndexGenerations().entrySet()) {
        final Index index = entry.getKey();
        final long generation = entry.getValue();
        final String indexFolderName = index.getUUID();
        final IndexMetaData indexMetaData = INDEX_META_DATA_FORMAT.loadGeneration(LOGGER, namedXContentRegistry, generation,
                nodeEnv.resolveIndexFolder(indexFolderName));
        if (indexMetaData != null) {
            metaDataBuilder.put(indexMetaData, false);
        } else {
            throw new IOException("failed to find metadata for existing index " + index.getName() + " [location: " + indexFolderName +
                    ", generation: " + generation + "]");
        }
    }

    return new Tuple<>(manifest, metaDataBuilder.build());
}
 
Example #11
Source File: NorwegianAnalyzerProvider.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Inject
public NorwegianAnalyzerProvider(Index index, IndexSettingsService indexSettingsService, Environment env, @Assisted String name, @Assisted Settings settings) {
    super(index, indexSettingsService.getSettings(), name, settings);
    analyzer = new NorwegianAnalyzer(Analysis.parseStopWords(env, settings, NorwegianAnalyzer.getDefaultStopSet()),
                                     Analysis.parseStemExclusion(settings, CharArraySet.EMPTY_SET));
    analyzer.setVersion(version);
}
 
Example #12
Source File: ChineseAnalyzerProvider.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Inject
public ChineseAnalyzerProvider(Index index, IndexSettingsService indexSettingsService, @Assisted String name, @Assisted Settings settings) {
    super(index, indexSettingsService.getSettings(), name, settings);
    // old index: best effort
    analyzer = new StandardAnalyzer();
    analyzer.setVersion(version);
    
}
 
Example #13
Source File: IcuCollationAnalyzerTests.java    From elasticsearch-plugin-bundle with GNU Affero General Public License v3.0 5 votes vote down vote up
public void testPrimaryStrengthFromJson() throws Exception {
    String resource = "icu_collation.json";
    Settings settings = Settings.builder()
            .loadFromStream(resource, getClass().getResourceAsStream(resource), true)
            .build();
    ESTestCase.TestAnalysis analysis = ESTestCase.createTestAnalysis(new Index("test", "_na_"),
            settings,
            new BundlePlugin(Settings.EMPTY));

    Analyzer analyzer = analysis.indexAnalyzers.get("icu_german_collate");

    String[] words = new String[]{
            "Göbel",
            "Goethe",
            "Goldmann",
            "Göthe",
            "Götz"
    };
    MultiMap<BytesRef,String> bytesRefMap = new TreeMultiMap<>();
    for (String s : words) {
        TokenStream ts = analyzer.tokenStream(null, s);
        bytesRefMap.put(bytesFromTokenStream(ts), s);
    }
    Iterator<Set<String>> it = bytesRefMap.values().iterator();
    assertEquals("[Göbel]",it.next().toString());
    assertEquals("[Goethe, Göthe]",it.next().toString());
    assertEquals("[Götz]",it.next().toString());
    assertEquals("[Goldmann]",it.next().toString());
}
 
Example #14
Source File: IndexNameExpressionResolver.java    From crate with Apache License 2.0 5 votes vote down vote up
String[] concreteIndexNames(Context context, String... indexExpressions) {
    Index[] indexes = concreteIndices(context, indexExpressions);
    String[] names = new String[indexes.length];
    for (int i = 0; i < indexes.length; i++) {
        names[i] = indexes[i].getName();
    }
    return names;
}
 
Example #15
Source File: EngineTestCase.java    From crate with Apache License 2.0 5 votes vote down vote up
public static void concurrentlyApplyOps(List<Engine.Operation> ops, InternalEngine engine) throws InterruptedException {
    Thread[] thread = new Thread[randomIntBetween(3, 5)];
    CountDownLatch startGun = new CountDownLatch(thread.length);
    AtomicInteger offset = new AtomicInteger(-1);
    for (int i = 0; i < thread.length; i++) {
        thread[i] = new Thread(() -> {
            startGun.countDown();
            try {
                startGun.await();
            } catch (InterruptedException e) {
                throw new AssertionError(e);
            }
            int docOffset;
            while ((docOffset = offset.incrementAndGet()) < ops.size()) {
                try {
                    final Engine.Operation op = ops.get(docOffset);
                    if (op instanceof Engine.Index) {
                        engine.index((Engine.Index) op);
                    } else if (op instanceof Engine.Delete) {
                        engine.delete((Engine.Delete) op);
                    } else {
                        engine.noOp((Engine.NoOp) op);
                    }
                    if ((docOffset + 1) % 4 == 0) {
                        engine.refresh("test");
                    }
                    if (rarely()) {
                        engine.flush();
                    }
                } catch (IOException e) {
                    throw new AssertionError(e);
                }
            }
        });
        thread[i].start();
    }
    for (int i = 0; i < thread.length; i++) {
        thread[i].join();
    }
}
 
Example #16
Source File: AbstractIndexOrdinalsFieldData.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
protected AbstractIndexOrdinalsFieldData(Index index, Settings indexSettings, Names fieldNames, FieldDataType fieldDataType,
                                      IndexFieldDataCache cache, CircuitBreakerService breakerService) {
    super(index, indexSettings, fieldNames, fieldDataType, cache);
    final Map<String, Settings> groups = fieldDataType.getSettings().getGroups("filter");
    frequency = groups.get("frequency");
    regex = groups.get("regex");
    this.breakerService = breakerService;
}
 
Example #17
Source File: IndexSettingsModule.java    From crate with Apache License 2.0 5 votes vote down vote up
public static IndexSettings newIndexSettings(Index index, Settings settings, IndexScopedSettings indexScopedSettings) {
    Settings build = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT)
            .put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 1)
            .put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1)
            .put(settings)
            .build();
    IndexMetaData metaData = IndexMetaData.builder(index.getName()).settings(build).build();
    return new IndexSettings(metaData, Settings.EMPTY, indexScopedSettings);
}
 
Example #18
Source File: ShardId.java    From crate with Apache License 2.0 5 votes vote down vote up
/**
 * Parse the string representation of this shardId back to an object.
 * We lose index uuid information here, but since we use toString in
 * rest responses, this is the best we can do to reconstruct the object
 * on the client side.
 */
public static ShardId fromString(String shardIdString) {
    int splitPosition = shardIdString.indexOf("][");
    if (splitPosition <= 0 || shardIdString.charAt(0) != '[' || shardIdString.charAt(shardIdString.length() - 1) != ']') {
        throw new IllegalArgumentException("Unexpected shardId string format, expected [indexName][shardId] but got " + shardIdString);
    }
    String indexName = shardIdString.substring(1, splitPosition);
    int shardId = Integer.parseInt(shardIdString.substring(splitPosition + 2, shardIdString.length() - 1));
    return new ShardId(new Index(indexName, IndexMetaData.INDEX_UUID_NA_VALUE), shardId);
}
 
Example #19
Source File: FstDecompoundTokenFilterTests.java    From elasticsearch-plugin-bundle with GNU Affero General Public License v3.0 5 votes vote down vote up
public void testDecompound() throws Exception {

        String source = "Die Jahresfeier der Rechtsanwaltskanzleien auf dem Donaudampfschiff hat viel Ökosteuer gekostet";

        String[] expected = {
                "Die",
                "Jahresfeier",
                "jahres",
                "feier",
                "der",
                "Rechtsanwaltskanzleien",
                "rechts",
                "anwalts",
                "kanzleien",
                "auf",
                "dem",
                "Donaudampfschiff",
                "donau",
                "dampf",
                "schiff",
                "hat",
                "viel",
                "Ökosteuer",
                "ökos",
                "teuer",
                "gekostet"
        };

        Settings settings = Settings.builder()
                .put("index.analysis.analyzer.myanalyzer.type", "custom")
                .put("index.analysis.analyzer.myanalyzer.tokenizer", "standard")
                .put("index.analysis.analyzer.myanalyzer.filter.0", "fst_decompound")
                .put("index.analysis.analyzer.myanalyzer.filter.1", "unique")
                .build();
        ESTestCase.TestAnalysis analysis = ESTestCase.createTestAnalysis(new Index("test", "_na_"),
                settings,
                new BundlePlugin(Settings.EMPTY), new CommonAnalysisPlugin());
        Analyzer myanalyzer = analysis.indexAnalyzers.get("myanalyzer");
        assertAnalyzesTo(myanalyzer, source, expected);
    }
 
Example #20
Source File: TransportBulkAction.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
private boolean addFailureIfIndexIsUnavailable(DocumentRequest request, BulkRequest bulkRequest, AtomicArray<BulkItemResponse> responses, int idx,
                                          final ConcreteIndices concreteIndices,
                                          final MetaData metaData) {
    String concreteIndex = concreteIndices.getConcreteIndex(request.index());
    Exception unavailableException = null;
    if (concreteIndex == null) {
        try {
            concreteIndex = concreteIndices.resolveIfAbsent(request);
        } catch (IndexClosedException | IndexNotFoundException ex) {
            // Fix for issue where bulk request references an index that
            // cannot be auto-created see issue #8125
            unavailableException = ex;
        }
    }
    if (unavailableException == null) {
        IndexMetaData indexMetaData = metaData.index(concreteIndex);
        if (indexMetaData.getState() == IndexMetaData.State.CLOSE) {
            unavailableException = new IndexClosedException(new Index(metaData.index(request.index()).getIndex()));
        }
    }
    if (unavailableException != null) {
        BulkItemResponse.Failure failure = new BulkItemResponse.Failure(request.index(), request.type(), request.id(),
                unavailableException);
        String operationType = "unknown";
        if (request instanceof IndexRequest) {
            operationType = "index";
        } else if (request instanceof DeleteRequest) {
            operationType = "delete";
        } else if (request instanceof UpdateRequest) {
            operationType = "update";
        }
        BulkItemResponse bulkItemResponse = new BulkItemResponse(idx, operationType, failure);
        responses.set(idx, bulkItemResponse);
        // make sure the request gets never processed again
        bulkRequest.requests.set(idx, null);
        return true;
    }
    return false;
}
 
Example #21
Source File: ElasticsearchRequestSubmitterTest.java    From metron with Apache License 2.0 5 votes vote down vote up
@Test
public void searchShouldHandleShardFailure() throws InvalidSearchException, IOException {
  // mocks
  SearchResponse response = mock(SearchResponse.class);
  SearchRequest request = new SearchRequest();
  ShardSearchFailure fail = mock(ShardSearchFailure.class);
  SearchShardTarget target = new SearchShardTarget("node1", mock(Index.class), 1, "metron");

  // response will have status of OK
  when(response.status()).thenReturn(RestStatus.OK);

  // response will indicate 1 search hit
  SearchHits hits = mock(SearchHits.class);
  when(hits.getTotalHits()).thenReturn(1L);

  // the response will report shard failures
  when(response.getFailedShards()).thenReturn(1);
  when(response.getTotalShards()).thenReturn(2);
  when(response.getHits()).thenReturn(hits);

  // the response will return the failures
  ShardSearchFailure[] failures = { fail };
  when(response.getShardFailures()).thenReturn(failures);

  // shard failure needs to report the node
  when(fail.shard()).thenReturn(target);

  // shard failure needs to report details of failure
  when(fail.index()).thenReturn("bro_index_2017-10-11");
  when(fail.shardId()).thenReturn(1);

  // search should succeed, even with failed shards
  ElasticsearchRequestSubmitter submitter = setup(response);
  SearchResponse actual = submitter.submitSearch(request);
  assertNotNull(actual);
}
 
Example #22
Source File: GermanNormalizationTests.java    From elasticsearch-plugin-bundle with GNU Affero General Public License v3.0 5 votes vote down vote up
public void testGerman1() throws IOException {

        String source = "Ein schöner Tag in Köln im Café an der Straßenecke";

        String[] expected = {
            "Ein",
            "schoner",
            "Tag",
            "in",
            "Koln",
            "im",
            "Café",
            "an",
            "der",
            "Strassenecke"
        };
        String resource = "german_normalization_analysis.json";
        Settings settings = Settings.builder()
                .put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT)
                .put("path.home", System.getProperty("path.home"))
                .loadFromStream(resource, getClass().getResourceAsStream(resource), true)
                .build();
        ESTestCase.TestAnalysis analysis = ESTestCase.createTestAnalysis(new Index("test", "_na_"),
                settings,
                new BundlePlugin(Settings.EMPTY));

        TokenFilterFactory tokenFilter = analysis.tokenFilter.get("umlaut");
        Tokenizer tokenizer = analysis.tokenizer.get("standard").create();
        tokenizer.setReader(new StringReader(source));
        assertTokenStreamContents(tokenFilter.create(tokenizer), expected);
    }
 
Example #23
Source File: GatewayMetaState.java    From crate with Apache License 2.0 5 votes vote down vote up
/**
 * Updates manifest and meta data on disk.
 *
 * @param newState new {@link ClusterState}
 * @param previousState previous {@link ClusterState}
 *
 * @throws WriteStateException if exception occurs. See also {@link WriteStateException#isDirty()}.
 */
protected void updateClusterState(ClusterState newState, ClusterState previousState)
        throws WriteStateException {
    MetaData newMetaData = newState.metaData();

    final AtomicClusterStateWriter writer = new AtomicClusterStateWriter(metaStateService, previousManifest);
    long globalStateGeneration = writeGlobalState(writer, newMetaData);
    Map<Index, Long> indexGenerations = writeIndicesMetadata(writer, newState, previousState);
    Manifest manifest = new Manifest(previousManifest.getCurrentTerm(), newState.version(), globalStateGeneration, indexGenerations);
    writeManifest(writer, manifest);

    previousManifest = manifest;
    previousClusterState = newState;
}
 
Example #24
Source File: IndexGraveyard.java    From crate with Apache License 2.0 5 votes vote down vote up
private Tombstone(final Index index, final long deleteDateInMillis) {
    Objects.requireNonNull(index);
    if (deleteDateInMillis < 0L) {
        throw new IllegalArgumentException("invalid deleteDateInMillis [" + deleteDateInMillis + "]");
    }
    this.index = index;
    this.deleteDateInMillis = deleteDateInMillis;
}
 
Example #25
Source File: IndicesService.java    From crate with Apache License 2.0 5 votes vote down vote up
/**
 * This method returns true if the current node is allowed to delete the given index.
 * This is the case if the index is deleted in the metadata or there is no allocation
 * on the local node and the index isn't on a shared file system.
 * @param index {@code Index} to check whether deletion is allowed
 * @param indexSettings {@code IndexSettings} for the given index
 * @return true if the index can be deleted on this node
 */
public boolean canDeleteIndexContents(Index index, IndexSettings indexSettings) {
    // index contents can be deleted if its an already closed index (so all its resources have
    // already been relinquished)
    final IndexService indexService = indexService(index);
    if (indexService == null && nodeEnv.hasNodeFile()) {
        return true;
    }
    return false;
}
 
Example #26
Source File: IndexShardRoutingTable.java    From crate with Apache License 2.0 5 votes vote down vote up
public static IndexShardRoutingTable readFromThin(StreamInput in, Index index) throws IOException {
    int iShardId = in.readVInt();
    ShardId shardId = new ShardId(index, iShardId);
    Builder builder = new Builder(shardId);

    int size = in.readVInt();
    for (int i = 0; i < size; i++) {
        ShardRouting shard = new ShardRouting(shardId, in);
        builder.addShard(shard);
    }

    return builder.build();
}
 
Example #27
Source File: InternalBlobTableInfoFactory.java    From crate with Apache License 2.0 5 votes vote down vote up
private IndexMetaData resolveIndexMetaData(String tableName, ClusterState state) {
    String indexName = BlobIndex.fullIndexName(tableName);
    Index index;
    try {
        index = indexNameExpressionResolver.concreteIndices(state, IndicesOptions.strictExpandOpen(), indexName)[0];
    } catch (IndexNotFoundException ex) {
        throw new RelationUnknown(indexName, ex);
    }
    return state.metaData().index(index);
}
 
Example #28
Source File: SearchService.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
private void freeAllContextForIndex(Index index) {
    assert index != null;
    for (SearchContext ctx : activeContexts.values()) {
        if (index.equals(ctx.indexShard().shardId().index())) {
            freeContext(ctx.id());
        }
    }
}
 
Example #29
Source File: MappingUpdatedAction.java    From crate with Apache License 2.0 5 votes vote down vote up
private PutMappingRequestBuilder updateMappingRequest(Index index, String type, Mapping mappingUpdate, final TimeValue timeout) {
    if (type.equals(MapperService.DEFAULT_MAPPING)) {
        throw new IllegalArgumentException("_default_ mapping should not be updated");
    }
    return client.preparePutMapping().setConcreteIndex(index).setType(type).setSource(mappingUpdate.toString(), XContentType.JSON)
            .setMasterNodeTimeout(timeout).setTimeout(timeout);
}
 
Example #30
Source File: EdgeNGramTokenizerFactory.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
public EdgeNGramTokenizerFactory(Index index, Settings indexSettings, String name, Settings settings) {
    super(index, indexSettings, name, settings);
    this.minGram = settings.getAsInt("min_gram", NGramTokenizer.DEFAULT_MIN_NGRAM_SIZE);
    this.maxGram = settings.getAsInt("max_gram", NGramTokenizer.DEFAULT_MAX_NGRAM_SIZE);
    this.side = Lucene43EdgeNGramTokenizer.Side.getSide(settings.get("side", Lucene43EdgeNGramTokenizer.DEFAULT_SIDE.getLabel()));
    this.matcher = parseTokenChars(settings.getAsArray("token_chars"));
    this.esVersion = org.elasticsearch.Version.indexCreated(indexSettings);
}