use of org.neo4j.internal.schema.IndexPrototype in project neo4j by neo4j.
the class SchemaRuleSerialization35Test method assertParseUniqueIndexRule.
private static void assertParseUniqueIndexRule(String serialized, String name) throws MalformedSchemaRuleException {
// GIVEN
long ruleId = 33;
long constraintId = 11;
IndexPrototype prototype = uniqueForLabelProto(61, 988).withIndexProvider(PROVIDER_25);
byte[] bytes = decodeBase64(serialized);
// WHEN
IndexDescriptor deserialized = assertIndexRule(SchemaRuleSerialization35.deserialize(ruleId, ByteBuffer.wrap(bytes)));
// THEN
assertThat(deserialized.getId()).isEqualTo(ruleId);
assertThat(deserialized).isEqualTo(prototype.withName(name).materialise(ruleId));
assertThat(deserialized.schema()).isEqualTo(prototype.schema());
assertThat(deserialized.getIndexProvider().getKey()).isEqualTo(PROVIDER_KEY);
assertThat(deserialized.getIndexProvider().getVersion()).isEqualTo(PROVIDER_VERSION_25);
assertThat(deserialized.getOwningConstraintId().isPresent()).isEqualTo(true);
assertThat(deserialized.getOwningConstraintId().getAsLong()).isEqualTo(constraintId);
assertThat(deserialized.getName()).isEqualTo(name);
}
use of org.neo4j.internal.schema.IndexPrototype in project neo4j by neo4j.
the class IndexSizesTest method createIndexes.
private void createIndexes(int numSmall, int numLarge) {
IndexCapability capabilityWithValue = mock(IndexCapability.class);
when(capabilityWithValue.valueCapability(any())).thenReturn(IndexValueCapability.YES);
IndexPrototype prototype = prototype();
for (int i = 0; i < numLarge; i++) {
// using id as "size"
indexes.add(prototype.materialise(highNodeId / 2 + i).withIndexCapability(capabilityWithValue));
}
for (int i = 0; i < numSmall; i++) {
// using id as "size"
indexes.add(prototype.materialise(i).withIndexCapability(capabilityWithValue));
}
try {
sizes.initialize();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of org.neo4j.internal.schema.IndexPrototype in project neo4j by neo4j.
the class Operations method indexCreate.
@Override
public IndexDescriptor indexCreate(SchemaDescriptor schema, String provider, IndexConfig indexConfig, String name) throws KernelException {
IndexProviderDescriptor providerDescriptor = indexProviders.indexProviderByName(provider);
IndexPrototype prototype = IndexPrototype.forSchema(schema, providerDescriptor).withName(name).withIndexConfig(indexConfig);
return indexCreate(prototype);
}
use of org.neo4j.internal.schema.IndexPrototype in project neo4j by neo4j.
the class FulltextIndexProviderTest method createIndex.
private IndexDescriptor createIndex(int[] entityTokens, int[] propertyIds, String analyzer, EntityType entityType, boolean eventuallyConsistent) throws KernelException {
IndexDescriptor fulltext;
try (KernelTransactionImplementation transaction = getKernelTransaction()) {
SchemaDescriptor schema = SchemaDescriptor.fulltext(entityType, entityTokens, propertyIds);
IndexConfig config = IndexConfig.with(FulltextIndexSettingsKeys.ANALYZER, Values.stringValue(analyzer)).withIfAbsent(FulltextIndexSettingsKeys.EVENTUALLY_CONSISTENT, Values.of(eventuallyConsistent));
IndexPrototype prototype = IndexPrototype.forSchema(schema, DESCRIPTOR).withIndexType(IndexType.FULLTEXT).withName(NAME).withIndexConfig(config);
fulltext = transaction.schemaWrite().indexCreate(prototype);
transaction.success();
}
return fulltext;
}
use of org.neo4j.internal.schema.IndexPrototype in project neo4j by neo4j.
the class FulltextIndexProviderTest method indexWithUnknownAnalyzerWillBeMarkedAsFailedOnStartup.
@Test
void indexWithUnknownAnalyzerWillBeMarkedAsFailedOnStartup() throws Exception {
// Create a full-text index.
long indexId;
try (KernelTransactionImplementation transaction = getKernelTransaction()) {
int[] propertyIds = { propIdHa };
SchemaDescriptor schema = SchemaDescriptor.fulltext(EntityType.NODE, new int[] { labelIdHa }, propertyIds);
IndexPrototype prototype = IndexPrototype.forSchema(schema).withIndexType(FULLTEXT).withName(NAME);
SchemaWrite schemaWrite = transaction.schemaWrite();
IndexDescriptor index = schemaWrite.indexCreate(prototype);
indexId = index.getId();
transaction.success();
}
// Modify the full-text index such that it has an analyzer configured that does not exist.
controller.restartDbms(builder -> {
var cacheTracer = NULL;
FileSystemAbstraction fs = builder.getFileSystem();
DatabaseLayout databaseLayout = Neo4jLayout.of(builder.getHomeDirectory()).databaseLayout(DEFAULT_DATABASE_NAME);
DefaultIdGeneratorFactory idGenFactory = new DefaultIdGeneratorFactory(fs, RecoveryCleanupWorkCollector.ignore(), databaseLayout.getDatabaseName());
try (JobScheduler scheduler = JobSchedulerFactory.createInitialisedScheduler();
PageCache pageCache = StandalonePageCacheFactory.createPageCache(fs, scheduler, cacheTracer)) {
StoreFactory factory = new StoreFactory(databaseLayout, Config.defaults(), idGenFactory, pageCache, fs, NullLogProvider.getInstance(), cacheTracer, writable());
var cursorContext = CursorContext.NULL;
try (NeoStores neoStores = factory.openAllNeoStores(false)) {
TokenHolders tokens = StoreTokens.readOnlyTokenHolders(neoStores, CursorContext.NULL);
SchemaStore schemaStore = neoStores.getSchemaStore();
SchemaStorage storage = new SchemaStorage(schemaStore, tokens, () -> KernelVersion.LATEST);
IndexDescriptor index = (IndexDescriptor) storage.loadSingleSchemaRule(indexId, CursorContext.NULL);
Map<String, Value> indexConfigMap = new HashMap<>(index.getIndexConfig().asMap());
for (Map.Entry<String, Value> entry : indexConfigMap.entrySet()) {
if (entry.getKey().contains("analyzer")) {
// This analyzer does not exist!
entry.setValue(Values.stringValue("bla-bla-lyzer"));
}
}
index = index.withIndexConfig(IndexConfig.with(indexConfigMap));
storage.writeSchemaRule(index, cursorContext, INSTANCE);
schemaStore.flush(cursorContext);
}
} catch (Exception e) {
throw new RuntimeException(e);
}
return builder;
});
// Verify that the index comes up in a failed state.
try (Transaction tx = db.beginTx()) {
IndexDefinition index = tx.schema().getIndexByName(NAME);
Schema.IndexState indexState = tx.schema().getIndexState(index);
assertThat(indexState).isEqualTo(Schema.IndexState.FAILED);
String indexFailure = tx.schema().getIndexFailure(index);
assertThat(indexFailure).contains("bla-bla-lyzer");
}
// Verify that the failed index can be dropped.
try (Transaction tx = db.beginTx()) {
tx.schema().getIndexByName(NAME).drop();
assertThrows(IllegalArgumentException.class, () -> tx.schema().getIndexByName(NAME));
tx.commit();
}
try (Transaction tx = db.beginTx()) {
assertThrows(IllegalArgumentException.class, () -> tx.schema().getIndexByName(NAME));
}
controller.restartDbms();
try (Transaction tx = db.beginTx()) {
assertThrows(IllegalArgumentException.class, () -> tx.schema().getIndexByName(NAME));
}
}
Aggregations