Search in sources :

Example 1 with IndexSettings

use of io.zulia.message.ZuliaIndex.IndexSettings in project zuliasearch by zuliaio.

the class ZuliaIndex method reloadIndexSettings.

public void reloadIndexSettings() throws Exception {
    IndexSettings indexSettings = indexService.getIndex(indexName);
    indexConfig.configure(indexSettings);
    configureFacets();
    zuliaPerFieldAnalyzer.refresh();
    for (ZuliaShard s : primaryShardMap.values()) {
        try {
            s.updateIndexSettings();
        } catch (Exception ignored) {
        }
    }
    for (ZuliaShard s : replicaShardMap.values()) {
        try {
            s.updateIndexSettings();
        } catch (Exception ignored) {
        }
    }
}
Also used : IndexSettings(io.zulia.message.ZuliaIndex.IndexSettings) ParseException(org.apache.lucene.queryparser.classic.ParseException) ShardDoesNotExistException(io.zulia.server.exceptions.ShardDoesNotExistException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException)

Example 2 with IndexSettings

use of io.zulia.message.ZuliaIndex.IndexSettings in project zuliasearch by zuliaio.

the class ClientIndexConfig method getIndexSettings.

public IndexSettings getIndexSettings() {
    IndexSettings.Builder isb = IndexSettings.newBuilder();
    if (numberOfShards != null) {
        isb.setNumberOfShards(numberOfShards);
    }
    if (indexName != null) {
        isb.setIndexName(indexName);
    }
    if (defaultSearchFields != null) {
        isb.addAllDefaultSearchField(defaultSearchFields);
    }
    if (requestFactor != null) {
        isb.setRequestFactor(requestFactor);
    }
    if (minShardRequest != null) {
        isb.setMinShardRequest(minShardRequest);
    }
    if (shardCommitInterval != null) {
        isb.setShardCommitInterval(shardCommitInterval);
    }
    if (idleTimeWithoutCommit != null) {
        isb.setIdleTimeWithoutCommit(idleTimeWithoutCommit);
    }
    if (shardTolerance != null) {
        isb.setShardTolerance(shardTolerance);
    }
    if (indexWeight != null) {
        isb.setIndexWeight(indexWeight);
    }
    if (ramBufferMB != null) {
        isb.setRamBufferMB(ramBufferMB);
    }
    for (String fieldName : fieldMap.keySet()) {
        FieldConfig fieldConfig = fieldMap.get(fieldName);
        isb.addFieldConfig(fieldConfig);
    }
    for (String analyzerName : analyzerSettingsMap.keySet()) {
        isb.addAnalyzerSettings(analyzerSettingsMap.get(analyzerName));
    }
    return isb.build();
}
Also used : FieldConfig(io.zulia.message.ZuliaIndex.FieldConfig) IndexSettings(io.zulia.message.ZuliaIndex.IndexSettings)

Example 3 with IndexSettings

use of io.zulia.message.ZuliaIndex.IndexSettings in project zuliasearch by zuliaio.

the class ZuliaIndexManager method loadIndex.

private void loadIndex(String indexName) throws Exception {
    IndexSettings indexSettings = indexService.getIndex(indexName);
    loadIndex(indexSettings);
}
Also used : IndexSettings(io.zulia.message.ZuliaIndex.IndexSettings)

Example 4 with IndexSettings

use of io.zulia.message.ZuliaIndex.IndexSettings in project zuliasearch by zuliaio.

the class ZuliaIndexManager method createIndex.

public CreateIndexResponse createIndex(CreateIndexRequest request) throws Exception {
    // if existing index make sure not to allow changing number of shards
    LOG.info(getLogPrefix() + " creating index: " + request);
    request = new CreateIndexRequestValidator().validateAndSetDefault(request);
    if (!request.hasIndexSettings()) {
        throw new IllegalArgumentException("Index settings field is required for create index");
    }
    NodeWeightComputation nodeWeightComputation = new DefaultNodeWeightComputation(indexService, thisNode, currentOtherNodesActive);
    IndexSettings indexSettings = request.getIndexSettings();
    if (indexSettings.getNumberOfShards() == 0) {
        indexSettings = indexSettings.toBuilder().setNumberOfShards(1).build();
    } else if (indexSettings.getNumberOfShards() < 0) {
        throw new IllegalArgumentException("Number of shards cannot be negative");
    }
    String indexName = indexSettings.getIndexName();
    IndexSettings existingIndex = indexService.getIndex(indexName);
    long currentTimeMillis = System.currentTimeMillis();
    if (existingIndex == null) {
        indexSettings = indexSettings.toBuilder().setCreateTime(currentTimeMillis).build();
        IndexMapping.Builder indexMapping = IndexMapping.newBuilder();
        indexMapping.setIndexName(indexName);
        indexMapping.setNumberOfShards(indexSettings.getNumberOfShards());
        for (int i = 0; i < indexSettings.getNumberOfShards(); i++) {
            List<Node> nodes = nodeWeightComputation.getNodesSortedByWeight();
            ShardMapping.Builder shardMapping = ShardMapping.newBuilder();
            Node primaryNode = nodes.remove(0);
            shardMapping.setPrimaryNode(primaryNode);
            shardMapping.setShardNumber(i);
            nodeWeightComputation.addShard(primaryNode, indexSettings, true);
            for (int r = 0; r < nodes.size(); r++) {
                if (r < indexSettings.getNumberOfReplicas()) {
                    Node replicaNode = nodes.get(r);
                    shardMapping.addReplicaNode(replicaNode);
                    nodeWeightComputation.addShard(replicaNode, indexSettings, false);
                } else {
                    break;
                }
            }
            indexMapping.addShardMapping(shardMapping);
        }
        indexService.storeIndexMapping(indexMapping.build());
    } else {
        if (existingIndex.equals(indexSettings)) {
            LOG.info("No changes to existing index <" + indexName + ">");
            return CreateIndexResponse.newBuilder().build();
        }
        if (existingIndex.getNumberOfShards() != indexSettings.getNumberOfShards()) {
            throw new IllegalArgumentException("Cannot change shards for existing index");
        }
        // TODO handle changing of replication factor
        if (existingIndex.getNumberOfReplicas() != indexSettings.getNumberOfReplicas()) {
            throw new IllegalArgumentException("Cannot change replication factor for existing index yet");
        }
    }
    indexSettings = indexSettings.toBuilder().setUpdateTime(currentTimeMillis).build();
    indexService.storeIndex(indexSettings);
    CreateIndexRequestFederator createIndexRequestFederator = new CreateIndexRequestFederator(thisNode, currentOtherNodesActive, pool, internalClient, this);
    try {
        @SuppressWarnings("unused") List<CreateIndexResponse> send = createIndexRequestFederator.send(InternalCreateIndexRequest.newBuilder().setIndexName(indexName).build());
    } catch (Exception e) {
        if (existingIndex == null) {
            LOG.log(Level.SEVERE, "Failed to update index <" + request.getIndexSettings().getIndexName() + ">: ", e);
            throw new Exception("Failed to update index <" + request.getIndexSettings().getIndexName() + ">: " + e.getMessage());
        } else {
            throw new Exception("Failed to create index <" + request.getIndexSettings().getIndexName() + ">: " + e.getMessage());
        }
    }
    return CreateIndexResponse.newBuilder().build();
}
Also used : CreateIndexRequestValidator(io.zulia.server.connection.server.validation.CreateIndexRequestValidator) IndexSettings(io.zulia.message.ZuliaIndex.IndexSettings) Node(io.zulia.message.ZuliaBase.Node) ZuliaNode(io.zulia.server.node.ZuliaNode) IndexDoesNotExistException(io.zulia.server.exceptions.IndexDoesNotExistException) IOException(java.io.IOException) IndexMapping(io.zulia.message.ZuliaIndex.IndexMapping) CreateIndexRequestFederator(io.zulia.server.index.federator.CreateIndexRequestFederator) ShardMapping(io.zulia.message.ZuliaIndex.ShardMapping)

Example 5 with IndexSettings

use of io.zulia.message.ZuliaIndex.IndexSettings in project zuliasearch by zuliaio.

the class MongoIndexService method getIndexSettingsFromDoc.

private IndexSettings getIndexSettingsFromDoc(Document doc) throws InvalidProtocolBufferException {
    Document indexSettingsDoc = (Document) doc.get(INDEX_SETTINGS);
    IndexSettings.Builder builder = IndexSettings.newBuilder();
    JsonFormat.parser().merge(indexSettingsDoc.toJson(), builder);
    return builder.build();
}
Also used : IndexSettings(io.zulia.message.ZuliaIndex.IndexSettings) Document(org.bson.Document)

Aggregations

IndexSettings (io.zulia.message.ZuliaIndex.IndexSettings)5 IOException (java.io.IOException)2 Node (io.zulia.message.ZuliaBase.Node)1 FieldConfig (io.zulia.message.ZuliaIndex.FieldConfig)1 IndexMapping (io.zulia.message.ZuliaIndex.IndexMapping)1 ShardMapping (io.zulia.message.ZuliaIndex.ShardMapping)1 CreateIndexRequestValidator (io.zulia.server.connection.server.validation.CreateIndexRequestValidator)1 IndexDoesNotExistException (io.zulia.server.exceptions.IndexDoesNotExistException)1 ShardDoesNotExistException (io.zulia.server.exceptions.ShardDoesNotExistException)1 CreateIndexRequestFederator (io.zulia.server.index.federator.CreateIndexRequestFederator)1 ZuliaNode (io.zulia.server.node.ZuliaNode)1 ExecutionException (java.util.concurrent.ExecutionException)1 ParseException (org.apache.lucene.queryparser.classic.ParseException)1 Document (org.bson.Document)1