org.elasticsearch.cluster.metadata.IndexMetaData Java Examples
The following examples show how to use
org.elasticsearch.cluster.metadata.IndexMetaData.
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: BlobStoreRepository.java From Elasticsearch with Apache License 2.0 | 6 votes |
/** * {@inheritDoc} */ @Override protected void doStart() { this.snapshotsBlobContainer = blobStore().blobContainer(basePath()); indexShardRepository.initialize(blobStore(), basePath(), chunkSize(), snapshotRateLimiter, restoreRateLimiter, this, isCompress()); ParseFieldMatcher parseFieldMatcher = new ParseFieldMatcher(settings); globalMetaDataFormat = new ChecksumBlobStoreFormat<>(METADATA_CODEC, METADATA_NAME_FORMAT, MetaData.PROTO, parseFieldMatcher, isCompress()); globalMetaDataLegacyFormat = new LegacyBlobStoreFormat<>(LEGACY_METADATA_NAME_FORMAT, MetaData.PROTO, parseFieldMatcher); indexMetaDataFormat = new ChecksumBlobStoreFormat<>(INDEX_METADATA_CODEC, METADATA_NAME_FORMAT, IndexMetaData.PROTO, parseFieldMatcher, isCompress()); indexMetaDataLegacyFormat = new LegacyBlobStoreFormat<>(LEGACY_SNAPSHOT_NAME_FORMAT, IndexMetaData.PROTO, parseFieldMatcher); snapshotFormat = new ChecksumBlobStoreFormat<>(SNAPSHOT_CODEC, SNAPSHOT_NAME_FORMAT, Snapshot.PROTO, parseFieldMatcher, isCompress()); snapshotLegacyFormat = new LegacyBlobStoreFormat<>(LEGACY_SNAPSHOT_NAME_FORMAT, Snapshot.PROTO, parseFieldMatcher); }
Example #2
Source File: OperationTest.java From crate with Apache License 2.0 | 6 votes |
@Test public void testBuildFromSingleIndexBlocks() throws Exception { assertThat(Operation.buildFromIndexSettingsAndState(Settings.builder().put( IndexMetaData.SETTING_READ_ONLY, true).build(), IndexMetaData.State.OPEN), is(Operation.READ_ONLY)); assertThat(Operation.buildFromIndexSettingsAndState(Settings.builder() .put(IndexMetaData.SETTING_BLOCKS_READ, true).build(), IndexMetaData.State.OPEN), containsInAnyOrder(Operation.UPDATE, Operation.INSERT, Operation.DELETE, Operation.DROP, Operation.ALTER, Operation.ALTER_OPEN_CLOSE, Operation.ALTER_BLOCKS, Operation.REFRESH, Operation.OPTIMIZE, Operation.ALTER_REROUTE)); assertThat(Operation.buildFromIndexSettingsAndState(Settings.builder() .put(IndexMetaData.SETTING_BLOCKS_WRITE, true).build(), IndexMetaData.State.OPEN), containsInAnyOrder(Operation.READ, Operation.ALTER, Operation.ALTER_OPEN_CLOSE, Operation.ALTER_BLOCKS, Operation.SHOW_CREATE, Operation.REFRESH, Operation.OPTIMIZE, Operation.COPY_TO, Operation.CREATE_SNAPSHOT, Operation.ALTER_REROUTE)); assertThat(Operation.buildFromIndexSettingsAndState(Settings.builder() .put(IndexMetaData.SETTING_BLOCKS_METADATA, true).build(), IndexMetaData.State.OPEN), containsInAnyOrder(Operation.READ, Operation.UPDATE, Operation.INSERT, Operation.DELETE, Operation.ALTER_BLOCKS, Operation.ALTER_OPEN_CLOSE, Operation.REFRESH, Operation.SHOW_CREATE, Operation.OPTIMIZE, Operation.ALTER_REROUTE)); }
Example #3
Source File: IndexRoutingTable.java From Elasticsearch with Apache License 2.0 | 6 votes |
/** * Initializes an index, to be restored from snapshot */ private Builder initializeAsRestore(IndexMetaData indexMetaData, RestoreSource restoreSource, IntSet ignoreShards, boolean asNew, UnassignedInfo unassignedInfo) { if (!shards.isEmpty()) { throw new IllegalStateException("trying to initialize an index with fresh shards, but already has shards created"); } for (int shardId = 0; shardId < indexMetaData.getNumberOfShards(); shardId++) { IndexShardRoutingTable.Builder indexShardRoutingBuilder = new IndexShardRoutingTable.Builder(new ShardId(indexMetaData.getIndex(), shardId)); for (int i = 0; i <= indexMetaData.getNumberOfReplicas(); i++) { if (asNew && ignoreShards.contains(shardId)) { // This shards wasn't completely snapshotted - restore it as new shard indexShardRoutingBuilder.addShard(ShardRouting.newUnassigned(index, shardId, null, i == 0, unassignedInfo)); } else { indexShardRoutingBuilder.addShard(ShardRouting.newUnassigned(index, shardId, i == 0 ? restoreSource : null, i == 0, unassignedInfo)); } } shards.put(shardId, indexShardRoutingBuilder.build()); } return this; }
Example #4
Source File: DocIndexMetaData.java From Elasticsearch with Apache License 2.0 | 6 votes |
public DocIndexMetaData(Functions functions, IndexMetaData metaData, TableIdent ident) throws IOException { this.functions = functions; this.ident = ident; this.metaData = metaData; this.isAlias = !metaData.getIndex().equals(ident.indexName()); this.numberOfShards = metaData.getNumberOfShards(); Settings settings = metaData.getSettings(); this.numberOfReplicas = NumberOfReplicas.fromSettings(settings); this.aliases = ImmutableSet.copyOf(metaData.getAliases().keys().toArray(String.class)); this.defaultMappingMetaData = this.metaData.mappingOrDefault(Constants.DEFAULT_MAPPING_TYPE); if (defaultMappingMetaData == null) { this.defaultMappingMap = ImmutableMap.of(); } else { this.defaultMappingMap = this.defaultMappingMetaData.sourceAsMap(); } this.tableParameters = TableParameterInfo.tableParametersFromIndexMetaData(metaData); Map<String, Object> metaMap = getNested(defaultMappingMap, "_meta"); indicesMap = getNested(metaMap, "indices", ImmutableMap.<String, Object>of()); partitionedByList = getNested(metaMap, "partitioned_by", ImmutableList.<List<String>>of()); generatedColumns = getNested(metaMap, "generated_columns", ImmutableMap.<String, String>of()); }
Example #5
Source File: InternalClusterInfoService.java From Elasticsearch with Apache License 2.0 | 6 votes |
static void buildShardLevelInfo(ESLogger logger, ShardStats[] stats, HashMap<String, Long> newShardSizes, HashMap<ShardRouting, String> newShardRoutingToDataPath, ClusterState state) { MetaData meta = state.getMetaData(); for (ShardStats s : stats) { IndexMetaData indexMeta = meta.index(s.getShardRouting().index()); Settings indexSettings = indexMeta == null ? null : indexMeta.getSettings(); newShardRoutingToDataPath.put(s.getShardRouting(), s.getDataPath()); long size = s.getStats().getStore().sizeInBytes(); String sid = ClusterInfo.shardIdentifierFromRouting(s.getShardRouting()); if (logger.isTraceEnabled()) { logger.trace("shard: {} size: {}", sid, size); } if (indexSettings != null && IndexMetaData.isIndexUsingShadowReplicas(indexSettings)) { // Shards on a shared filesystem should be considered of size 0 if (logger.isTraceEnabled()) { logger.trace("shard: {} is using shadow replicas and will be treated as size 0", sid); } size = 0; } newShardSizes.put(sid, size); } }
Example #6
Source File: GatewayMetaState.java From crate with Apache License 2.0 | 6 votes |
/** * Elasticsearch 2.0 removed several deprecated features and as well as support for Lucene 3.x. This method calls * {@link MetaDataIndexUpgradeService} to makes sure that indices are compatible with the current version. The * MetaDataIndexUpgradeService might also update obsolete settings if needed. * Allows upgrading global custom meta data via {@link MetaDataUpgrader#customMetaDataUpgraders} * * @return input <code>metaData</code> if no upgrade is needed or an upgraded metaData */ static MetaData upgradeMetaData(MetaData metaData, MetaDataIndexUpgradeService metaDataIndexUpgradeService, MetaDataUpgrader metaDataUpgrader) { // upgrade index meta data boolean changed = false; final MetaData.Builder upgradedMetaData = MetaData.builder(metaData); for (IndexMetaData indexMetaData : metaData) { IndexMetaData newMetaData = metaDataIndexUpgradeService.upgradeIndexMetaData(indexMetaData, Version.CURRENT.minimumIndexCompatibilityVersion()); changed |= indexMetaData != newMetaData; upgradedMetaData.put(newMetaData, false); } // upgrade global custom meta data if (applyPluginUpgraders(metaData.getCustoms(), metaDataUpgrader.customMetaDataUpgraders, upgradedMetaData::removeCustom, upgradedMetaData::putCustom)) { changed = true; } // upgrade current templates if (applyPluginUpgraders(metaData.getTemplates(), metaDataUpgrader.indexTemplateMetaDataUpgraders, upgradedMetaData::removeTemplate, (s, indexTemplateMetaData) -> upgradedMetaData.put(indexTemplateMetaData))) { changed = true; } return changed ? upgradedMetaData.build() : metaData; }
Example #7
Source File: GatewayMetaState.java From Elasticsearch with Apache License 2.0 | 6 votes |
/** * Loads the current meta state for each index in the new cluster state and checks if it has to be persisted. * Each index state that should be written to disk will be returned. This is only run for data only nodes. * It will return only the states for indices that actually have a shard allocated on the current node. * * @param previouslyWrittenIndices A list of indices for which the state was already written before * @param potentiallyUnwrittenIndices The list of indices for which state should potentially be written * @param previousMetaData The last meta data we know of. meta data for all indices in previouslyWrittenIndices list is persisted now * @param newMetaData The new metadata * @return iterable over all indices states that should be written to disk */ public static Iterable<GatewayMetaState.IndexMetaWriteInfo> resolveStatesToBeWritten(ImmutableSet<String> previouslyWrittenIndices, Set<String> potentiallyUnwrittenIndices, MetaData previousMetaData, MetaData newMetaData) { List<GatewayMetaState.IndexMetaWriteInfo> indicesToWrite = new ArrayList<>(); for (String index : potentiallyUnwrittenIndices) { IndexMetaData newIndexMetaData = newMetaData.index(index); IndexMetaData previousIndexMetaData = previousMetaData == null ? null : previousMetaData.index(index); String writeReason = null; if (previouslyWrittenIndices.contains(index) == false || previousIndexMetaData == null) { writeReason = "freshly created"; } else if (previousIndexMetaData.getVersion() != newIndexMetaData.getVersion()) { writeReason = "version changed from [" + previousIndexMetaData.getVersion() + "] to [" + newIndexMetaData.getVersion() + "]"; } if (writeReason != null) { indicesToWrite.add(new GatewayMetaState.IndexMetaWriteInfo(newIndexMetaData, previousIndexMetaData, writeReason)); } } return indicesToWrite; }
Example #8
Source File: SnapshotsService.java From crate with Apache License 2.0 | 6 votes |
/** * Returns list of indices with missing shards, and list of indices that are closed * * @param shards list of shard statuses * @return list of failed and closed indices */ private static Tuple<Set<String>, Set<String>> indicesWithMissingShards( ImmutableOpenMap<ShardId, SnapshotsInProgress.ShardSnapshotStatus> shards, MetaData metaData) { Set<String> missing = new HashSet<>(); Set<String> closed = new HashSet<>(); for (ObjectObjectCursor<ShardId, SnapshotsInProgress.ShardSnapshotStatus> entry : shards) { if (entry.value.state() == ShardState.MISSING) { if (metaData.hasIndex(entry.key.getIndex().getName()) && metaData.getIndexSafe(entry.key.getIndex()).getState() == IndexMetaData.State.CLOSE) { closed.add(entry.key.getIndex().getName()); } else { missing.add(entry.key.getIndex().getName()); } } } return new Tuple<>(missing, closed); }
Example #9
Source File: IndicesClusterStateService.java From Elasticsearch with Apache License 2.0 | 6 votes |
private void applySettings(ClusterChangedEvent event) { if (!event.metaDataChanged()) { return; } for (IndexMetaData indexMetaData : event.state().metaData()) { if (!indicesService.hasIndex(indexMetaData.getIndex())) { // we only create / update here continue; } // if the index meta data didn't change, no need check for refreshed settings if (!event.indexMetaDataChanged(indexMetaData)) { continue; } String index = indexMetaData.getIndex(); IndexService indexService = indicesService.indexService(index); if (indexService == null) { // already deleted on us, ignore it continue; } IndexSettingsService indexSettingsService = indexService.injector().getInstance(IndexSettingsService.class); indexSettingsService.refreshSettings(indexMetaData.getSettings()); } }
Example #10
Source File: ClusterBlocks.java From crate with Apache License 2.0 | 6 votes |
public Builder addBlocks(IndexMetaData indexMetaData) { String indexName = indexMetaData.getIndex().getName(); if (indexMetaData.getState() == IndexMetaData.State.CLOSE) { addIndexBlock(indexName, IndexMetaData.INDEX_CLOSED_BLOCK); } if (IndexMetaData.INDEX_READ_ONLY_SETTING.get(indexMetaData.getSettings())) { addIndexBlock(indexName, IndexMetaData.INDEX_READ_ONLY_BLOCK); } if (IndexMetaData.INDEX_BLOCKS_READ_SETTING.get(indexMetaData.getSettings())) { addIndexBlock(indexName, IndexMetaData.INDEX_READ_BLOCK); } if (IndexMetaData.INDEX_BLOCKS_WRITE_SETTING.get(indexMetaData.getSettings())) { addIndexBlock(indexName, IndexMetaData.INDEX_WRITE_BLOCK); } if (IndexMetaData.INDEX_BLOCKS_METADATA_SETTING.get(indexMetaData.getSettings())) { addIndexBlock(indexName, IndexMetaData.INDEX_METADATA_BLOCK); } if (IndexMetaData.INDEX_BLOCKS_READ_ONLY_ALLOW_DELETE_SETTING.get(indexMetaData.getSettings())) { addIndexBlock(indexName, IndexMetaData.INDEX_READ_ONLY_ALLOW_DELETE_BLOCK); } return this; }
Example #11
Source File: RestoreService.java From crate with Apache License 2.0 | 6 votes |
/** * Check if any of the indices to be closed are currently being restored from a snapshot and fail closing if such an index * is found as closing an index that is being restored makes the index unusable (it cannot be recovered). */ public static void checkIndexClosing(ClusterState currentState, Set<IndexMetaData> indices) { RestoreInProgress restore = currentState.custom(RestoreInProgress.TYPE); if (restore != null) { Set<Index> indicesToFail = null; for (RestoreInProgress.Entry entry : restore.entries()) { for (ObjectObjectCursor<ShardId, RestoreInProgress.ShardRestoreStatus> shard : entry.shards()) { if (!shard.value.state().completed()) { IndexMetaData indexMetaData = currentState.metaData().index(shard.key.getIndex()); if (indexMetaData != null && indices.contains(indexMetaData)) { if (indicesToFail == null) { indicesToFail = new HashSet<>(); } indicesToFail.add(shard.key.getIndex()); } } } } if (indicesToFail != null) { throw new IllegalArgumentException("Cannot close indices that are being restored: " + indicesToFail); } } }
Example #12
Source File: SQLExecutor.java From crate with Apache License 2.0 | 6 votes |
private static IndexMetaData.Builder getIndexMetaData(String indexName, Settings settings, @Nullable Map<String, Object> mapping, Version smallestNodeVersion) throws IOException { Settings.Builder builder = Settings.builder() .put(settings) .put(SETTING_VERSION_CREATED, smallestNodeVersion) .put(SETTING_CREATION_DATE, Instant.now().toEpochMilli()) .put(SETTING_INDEX_UUID, UUIDs.randomBase64UUID()); Settings indexSettings = builder.build(); IndexMetaData.Builder metaBuilder = IndexMetaData.builder(indexName) .settings(indexSettings); if (mapping != null) { metaBuilder.putMapping(new MappingMetaData( Constants.DEFAULT_MAPPING_TYPE, mapping)); } return metaBuilder; }
Example #13
Source File: PutIndexTemplateRequest.java From Elasticsearch with Apache License 2.0 | 6 votes |
@Override public void readFrom(StreamInput in) throws IOException { super.readFrom(in); cause = in.readString(); name = in.readString(); template = in.readString(); order = in.readInt(); create = in.readBoolean(); settings = readSettingsFromStream(in); int size = in.readVInt(); for (int i = 0; i < size; i++) { mappings.put(in.readString(), in.readString()); } int customSize = in.readVInt(); for (int i = 0; i < customSize; i++) { String type = in.readString(); IndexMetaData.Custom customIndexMetaData = IndexMetaData.lookupPrototypeSafe(type).readFrom(in); customs.put(type, customIndexMetaData); } int aliasesSize = in.readVInt(); for (int i = 0; i < aliasesSize; i++) { aliases.add(Alias.read(in)); } }
Example #14
Source File: DocIndexMetaDataTest.java From crate with Apache License 2.0 | 5 votes |
private IndexMetaData getIndexMetaData(String indexName, XContentBuilder builder) throws IOException { Map<String, Object> mappingSource = XContentHelper.convertToMap(BytesReference.bytes(builder), true, XContentType.JSON).v2(); mappingSource = sortProperties(mappingSource); Settings.Builder settingsBuilder = Settings.builder() .put("index.number_of_shards", 1) .put("index.number_of_replicas", 0) .put("index.version.created", org.elasticsearch.Version.CURRENT); IndexMetaData.Builder mdBuilder = IndexMetaData.builder(indexName) .settings(settingsBuilder) .putMapping(new MappingMetaData(Constants.DEFAULT_MAPPING_TYPE, mappingSource)); return mdBuilder.build(); }
Example #15
Source File: IndicesService.java From crate with Apache License 2.0 | 5 votes |
/** * creates a new mapper service for the given index, in order to do administrative work like mapping updates. * This *should not* be used for document parsing. Doing so will result in an exception. * * Note: the returned {@link MapperService} should be closed when unneeded. */ public synchronized MapperService createIndexMapperService(IndexMetaData indexMetaData) throws IOException { final IndexSettings idxSettings = new IndexSettings(indexMetaData, this.settings, indexScopedSettings); final IndexModule indexModule = new IndexModule(idxSettings, analysisRegistry, getEngineFactory(idxSettings), indexStoreFactories); pluginsService.onIndexModule(indexModule); return indexModule.newIndexMapperService(xContentRegistry, mapperRegistry); }
Example #16
Source File: LocalAllocateDangledIndices.java From Elasticsearch with Apache License 2.0 | 5 votes |
@Override public void writeTo(StreamOutput out) throws IOException { super.writeTo(out); fromNode.writeTo(out); out.writeVInt(indices.length); for (IndexMetaData indexMetaData : indices) { indexMetaData.writeTo(out); } }
Example #17
Source File: CreateAlterPartitionedTableAnalyzerTest.java From crate with Apache License 2.0 | 5 votes |
@Test public void testAlterPartitionedTableShards() { BoundAlterTable analysis = analyze( "alter table parted set (number_of_shards=10)"); assertThat(analysis.partitionName().isPresent(), is(false)); assertThat(analysis.isPartitioned(), is(true)); assertEquals("10", analysis.tableParameter().settings().get(IndexMetaData.INDEX_NUMBER_OF_SHARDS_SETTING.getKey())); }
Example #18
Source File: RestImportActionTest.java From elasticsearch-inout-plugin with Apache License 2.0 | 5 votes |
@Test public void testSettings() { String path = getClass().getResource("/importdata/import_9").getPath(); executeImportRequest("{\"directory\": \"" + path + "\", \"settings\": true}"); ClusterStateRequest clusterStateRequest = Requests.clusterStateRequest().filteredIndices("index1"); IndexMetaData stats = esSetup.client().admin().cluster().state(clusterStateRequest).actionGet().getState().metaData().index("index1"); assertEquals(2, stats.numberOfShards()); assertEquals(1, stats.numberOfReplicas()); }
Example #19
Source File: CreateAlterTableStatementAnalyzerTest.java From crate with Apache License 2.0 | 5 votes |
@Test public void testAlterTableResetShards() { BoundAlterTable analysis = analyze("alter table users reset (\"number_of_shards\")"); assertThat(analysis.table().ident().name(), is("users")); assertThat(analysis.tableParameter().settings().get(IndexMetaData.INDEX_NUMBER_OF_SHARDS_SETTING.getKey()), is("5")); }
Example #20
Source File: DanglingIndicesState.java From Elasticsearch with Apache License 2.0 | 5 votes |
/** * Finds new dangling indices by iterating over the indices and trying to find indices * that have state on disk, but are not part of the provided meta data, or not detected * as dangled already. */ Map<String, IndexMetaData> findNewDanglingIndices(MetaData metaData) { final Set<String> indices; try { indices = nodeEnv.findAllIndices(); } catch (Throwable e) { logger.warn("failed to list dangling indices", e); return ImmutableMap.of(); } Map<String, IndexMetaData> newIndices = Maps.newHashMap(); for (String indexName : indices) { if (metaData.hasIndex(indexName) == false && danglingIndices.containsKey(indexName) == false) { try { IndexMetaData indexMetaData = metaStateService.loadIndexState(indexName); if (indexMetaData != null) { logger.info("[{}] dangling index, exists on local file system, but not in cluster metadata, auto import to cluster state", indexName); if (!indexMetaData.getIndex().equals(indexName)) { logger.info("dangled index directory name is [{}], state name is [{}], renaming to directory name", indexName, indexMetaData.getIndex()); indexMetaData = IndexMetaData.builder(indexMetaData).index(indexName).build(); } newIndices.put(indexName, indexMetaData); } else { logger.debug("[{}] dangling index directory detected, but no state found", indexName); } } catch (Throwable t) { logger.warn("[{}] failed to load index state for detected dangled index", t, indexName); } } } return newIndices; }
Example #21
Source File: DDLClusterStateHelpers.java From crate with Apache License 2.0 | 5 votes |
static Set<IndexMetaData> indexMetaDataSetFromIndexNames(MetaData metaData, String[] indices, IndexMetaData.State state) { Set<IndexMetaData> indicesMetaData = new HashSet<>(); for (String indexName : indices) { IndexMetaData indexMetaData = metaData.index(indexName); if (indexMetaData != null && indexMetaData.getState() != state) { indicesMetaData.add(indexMetaData); } } return indicesMetaData; }
Example #22
Source File: MetaDataIndexUpgrader.java From crate with Apache License 2.0 | 5 votes |
/** * Purges any dynamic template from the index metadata because they might be out-dated and the general default * template will apply any defaults for all indices. */ private IndexMetaData createUpdatedIndexMetaData(IndexMetaData indexMetaData) { return IndexMetaData.builder(indexMetaData) .putMapping( createUpdatedIndexMetaData( indexMetaData.mapping(Constants.DEFAULT_MAPPING_TYPE), indexMetaData.getIndex().getName() )) .build(); }
Example #23
Source File: MetaStateService.java From Elasticsearch with Apache License 2.0 | 5 votes |
/** * Returns a StateFormat that can read and write {@link IndexMetaData} */ static MetaDataStateFormat<IndexMetaData> indexStateFormat(XContentType format, final ToXContent.Params formatParams) { return new MetaDataStateFormat<IndexMetaData>(format, INDEX_STATE_FILE_PREFIX) { @Override public void toXContent(XContentBuilder builder, IndexMetaData state) throws IOException { IndexMetaData.Builder.toXContent(state, builder, formatParams); } @Override public IndexMetaData fromXContent(XContentParser parser) throws IOException { return IndexMetaData.Builder.fromXContent(parser); } }; }
Example #24
Source File: ShardPath.java From crate with Apache License 2.0 | 5 votes |
/** * This method walks through the nodes shard paths to find the data and state path for the given shard. If multiple * directories with a valid shard state exist the one with the highest version will be used. * <b>Note:</b> this method resolves custom data locations for the shard. */ public static ShardPath loadShardPath(Logger logger, ShardId shardId, IndexSettings indexSettings, Path[] availableShardPaths, int nodeLockId, Path sharedDataPath) throws IOException { final String indexUUID = indexSettings.getUUID(); Path loadedPath = null; for (Path path : availableShardPaths) { // EMPTY is safe here because we never call namedObject ShardStateMetaData load = ShardStateMetaData.FORMAT.loadLatestState(logger, NamedXContentRegistry.EMPTY, path); if (load != null) { if (load.indexUUID.equals(indexUUID) == false && IndexMetaData.INDEX_UUID_NA_VALUE.equals(load.indexUUID) == false) { logger.warn("{} found shard on path: [{}] with a different index UUID - this " + "shard seems to be leftover from a different index with the same name. " + "Remove the leftover shard in order to reuse the path with the current index", shardId, path); throw new IllegalStateException(shardId + " index UUID in shard state was: " + load.indexUUID + " expected: " + indexUUID + " on shard path: " + path); } if (loadedPath == null) { loadedPath = path; } else { throw new IllegalStateException(shardId + " more than one shard state found"); } } } if (loadedPath == null) { return null; } else { final Path dataPath; final Path statePath = loadedPath; if (indexSettings.hasCustomDataPath()) { dataPath = NodeEnvironment.resolveCustomLocation(indexSettings, shardId, sharedDataPath, nodeLockId); } else { dataPath = statePath; } logger.debug("{} loaded data path [{}], state path [{}]", shardId, dataPath, statePath); return new ShardPath(indexSettings.hasCustomDataPath(), dataPath, statePath, shardId); } }
Example #25
Source File: TribeService.java From Elasticsearch with Apache License 2.0 | 5 votes |
private void addNewIndex(ClusterState tribeState, ClusterBlocks.Builder blocks, MetaData.Builder metaData, RoutingTable.Builder routingTable, IndexMetaData tribeIndex) { Settings tribeSettings = Settings.builder().put(tribeIndex.getSettings()).put(TRIBE_NAME, tribeName).build(); metaData.put(IndexMetaData.builder(tribeIndex).settings(tribeSettings)); routingTable.add(tribeState.routingTable().index(tribeIndex.getIndex())); if (Regex.simpleMatch(blockIndicesMetadata, tribeIndex.getIndex())) { blocks.addIndexBlock(tribeIndex.getIndex(), IndexMetaData.INDEX_METADATA_BLOCK); } if (Regex.simpleMatch(blockIndicesRead, tribeIndex.getIndex())) { blocks.addIndexBlock(tribeIndex.getIndex(), IndexMetaData.INDEX_READ_BLOCK); } if (Regex.simpleMatch(blockIndicesWrite, tribeIndex.getIndex())) { blocks.addIndexBlock(tribeIndex.getIndex(), IndexMetaData.INDEX_WRITE_BLOCK); } }
Example #26
Source File: DocSchemaInfo.java From crate with Apache License 2.0 | 5 votes |
/** * checks if metaData contains a particular index and * invalidates its aliases if so */ @VisibleForTesting void invalidateFromIndex(Index index, MetaData metaData) { IndexMetaData indexMetaData = metaData.index(index); if (indexMetaData != null) { invalidateAliases(indexMetaData.getAliases()); } }
Example #27
Source File: TableSettingsResolver.java From crate with Apache License 2.0 | 5 votes |
private static Settings forTable(MetaData metaData, RelationName relationName) { IndexMetaData indexMetaData = metaData.index(relationName.indexNameOrAlias()); if (indexMetaData == null) { throw new IndexNotFoundException(relationName.indexNameOrAlias()); } return indexMetaData.getSettings(); }
Example #28
Source File: DocIndexMetaDataTest.java From crate with Apache License 2.0 | 5 votes |
@Test public void testExtractCheckConstraints() throws Exception { XContentBuilder builder = XContentFactory.jsonBuilder() .startObject() .startObject(Constants.DEFAULT_MAPPING_TYPE) .startObject("_meta") .startObject("check_constraints") .field("test3_check_1", "id >= 0") .field("test3_check_2", "title != 'Programming Clojure'") .endObject() .endObject() .startObject("properties") .startObject("id").field("type", "integer").endObject() .startObject("title").field("type", "string").endObject() .endObject() .endObject() .endObject(); IndexMetaData metaData = getIndexMetaData("test3", builder); DocIndexMetaData md = newMeta(metaData, "test3"); assertThat(md.checkConstraints().size(), is(2)); assertThat(md.checkConstraints() .stream() .map(CheckConstraint::expressionStr) .collect(Collectors.toList()), containsInAnyOrder( equalTo("id >= 0"), equalTo("title != 'Programming Clojure'") )); }
Example #29
Source File: IndexSettingsModule.java From crate with Apache License 2.0 | 5 votes |
public static IndexSettings newIndexSettings(final IndexMetaData indexMetaData, Setting<?>... setting) { Set<Setting<?>> settingSet = new HashSet<>(IndexScopedSettings.BUILT_IN_INDEX_SETTINGS); if (setting.length > 0) { settingSet.addAll(Arrays.asList(setting)); } return new IndexSettings(indexMetaData, Settings.EMPTY, new IndexScopedSettings(Settings.EMPTY, settingSet)); }
Example #30
Source File: Version.java From crate with Apache License 2.0 | 5 votes |
/** * Return the {@link Version} of Elasticsearch that has been used to create an index given its settings. * * @throws IllegalStateException if the given index settings doesn't contain a value for the key * {@value IndexMetaData#SETTING_VERSION_CREATED} */ public static Version indexCreated(Settings indexSettings) { final Version indexVersion = IndexMetaData.SETTING_INDEX_VERSION_CREATED.get(indexSettings); if (indexVersion == V_EMPTY) { final String message = String.format( Locale.ROOT, "[%s] is not present in the index settings for index with UUID [%s]", IndexMetaData.SETTING_INDEX_VERSION_CREATED.getKey(), indexSettings.get(IndexMetaData.SETTING_INDEX_UUID)); throw new IllegalStateException(message); } return indexVersion; }