use of org.neo4j.kernel.impl.store.NeoStores in project neo4j by neo4j.
the class HighIdTransactionApplierTest method shouldUpdateHighIdsOnExternalTransaction.
@Test
public void shouldUpdateHighIdsOnExternalTransaction() throws Exception {
// GIVEN
NeoStores neoStores = neoStoresRule.open();
HighIdTransactionApplier tracker = new HighIdTransactionApplier(neoStores);
// WHEN
// Nodes
tracker.visitNodeCommand(Commands.createNode(10, 2, 3));
tracker.visitNodeCommand(Commands.createNode(20, 4, 5));
// Relationships
tracker.visitRelationshipCommand(Commands.createRelationship(4, 10, 20, 0));
tracker.visitRelationshipCommand(Commands.createRelationship(45, 10, 20, 1));
// Label tokens
tracker.visitLabelTokenCommand(Commands.createLabelToken(3, 0));
tracker.visitLabelTokenCommand(Commands.createLabelToken(5, 1));
// Property tokens
tracker.visitPropertyKeyTokenCommand(Commands.createPropertyKeyToken(3, 0));
tracker.visitPropertyKeyTokenCommand(Commands.createPropertyKeyToken(5, 1));
// Relationship type tokens
tracker.visitRelationshipTypeTokenCommand(Commands.createRelationshipTypeToken(3, 0));
tracker.visitRelationshipTypeTokenCommand(Commands.createRelationshipTypeToken(5, 1));
// Relationship groups
tracker.visitRelationshipGroupCommand(Commands.createRelationshipGroup(10, 1));
tracker.visitRelationshipGroupCommand(Commands.createRelationshipGroup(20, 2));
// Schema rules
tracker.visitSchemaRuleCommand(Commands.createIndexRule(NO_INDEX_PROVIDER.getProviderDescriptor(), 10, new NodePropertyDescriptor(0, 1)));
tracker.visitSchemaRuleCommand(Commands.createIndexRule(NO_INDEX_PROVIDER.getProviderDescriptor(), 20, new NodePropertyDescriptor(1, 2)));
// Properties
tracker.visitPropertyCommand(Commands.createProperty(10, PropertyType.STRING, 0, 6, 7));
tracker.visitPropertyCommand(Commands.createProperty(20, PropertyType.ARRAY, 1, 8, 9));
tracker.close();
// THEN
assertEquals("NodeStore", 20 + 1, neoStores.getNodeStore().getHighId());
assertEquals("DynamicNodeLabelStore", 5 + 1, neoStores.getNodeStore().getDynamicLabelStore().getHighId());
assertEquals("RelationshipStore", 45 + 1, neoStores.getRelationshipStore().getHighId());
assertEquals("RelationshipTypeStore", 5 + 1, neoStores.getRelationshipTypeTokenStore().getHighId());
assertEquals("RelationshipType NameStore", 1 + 1, neoStores.getRelationshipTypeTokenStore().getNameStore().getHighId());
assertEquals("PropertyKeyStore", 5 + 1, neoStores.getPropertyKeyTokenStore().getHighId());
assertEquals("PropertyKey NameStore", 1 + 1, neoStores.getPropertyKeyTokenStore().getNameStore().getHighId());
assertEquals("LabelStore", 5 + 1, neoStores.getLabelTokenStore().getHighId());
assertEquals("Label NameStore", 1 + 1, neoStores.getLabelTokenStore().getNameStore().getHighId());
assertEquals("PropertyStore", 20 + 1, neoStores.getPropertyStore().getHighId());
assertEquals("PropertyStore DynamicStringStore", 7 + 1, neoStores.getPropertyStore().getStringStore().getHighId());
assertEquals("PropertyStore DynamicArrayStore", 9 + 1, neoStores.getPropertyStore().getArrayStore().getHighId());
assertEquals("SchemaStore", 20 + 1, neoStores.getSchemaStore().getHighId());
}
use of org.neo4j.kernel.impl.store.NeoStores in project neo4j by neo4j.
the class DuplicatePropertyRemoverTest method setUp.
@BeforeClass
public static void setUp() {
GraphDatabaseFactory factory = new TestGraphDatabaseFactory();
GraphDatabaseService db = factory.newEmbeddedDatabase(storePath.absolutePath());
api = (GraphDatabaseAPI) db;
Label nodeLabel = Label.label("Label");
propertyNames = new ArrayList<>();
try (Transaction transaction = db.beginTx()) {
node = db.createNode(nodeLabel);
nodeId = node.getId();
for (int i = 0; i < PROPERTY_COUNT; i++) {
String propKey = "key" + i;
propertyNames.add(propKey);
String propValue = "value" + i;
boolean isBigProp = ThreadLocalRandom.current().nextBoolean();
if (isBigProp) {
propValue += propValue;
propValue += propValue;
propValue += propValue;
propValue += propValue;
propValue += propValue;
}
node.setProperty(propKey, propValue);
}
transaction.success();
}
Collections.shuffle(propertyNames);
DependencyResolver resolver = api.getDependencyResolver();
NeoStores neoStores = resolver.resolveDependency(RecordStorageEngine.class).testAccessNeoStores();
nodeStore = neoStores.getNodeStore();
PropertyKeyTokenStore propertyKeyTokenStore = neoStores.getPropertyKeyTokenStore();
indexedPropertyKeys = PropertyDeduplicatorTestUtil.indexPropertyKeys(propertyKeyTokenStore);
propertyStore = neoStores.getPropertyStore();
remover = new DuplicatePropertyRemover(nodeStore, propertyStore);
}
use of org.neo4j.kernel.impl.store.NeoStores in project neo4j by neo4j.
the class IndexConsultedPropertyBlockSweeperTest method setUp.
@Before
public void setUp() throws IOException {
api = dbRule.getGraphDatabaseAPI();
nonIndexedPropKey = "notIndexed";
indexedPropKey = "indexed";
Label usedLabel = Label.label("UsedLabel");
try (Transaction transaction = api.beginTx()) {
api.schema().indexFor(usedLabel).on(indexedPropKey).create();
transaction.success();
}
try (Transaction transaction = api.beginTx()) {
indexedValue = "value1";
nonIndexedValue = "value2";
Node nodeA = api.createNode(usedLabel);
nodeA.setProperty(indexedPropKey, indexedValue);
nodeA.setProperty(nonIndexedPropKey, nonIndexedValue);
nodeId = nodeA.getId();
transaction.success();
}
DependencyResolver resolver = api.getDependencyResolver();
NeoStores neoStores = resolver.resolveDependency(RecordStorageEngine.class).testAccessNeoStores();
nodeStore = neoStores.getNodeStore();
PropertyKeyTokenStore propertyKeyTokenStore = neoStores.getPropertyKeyTokenStore();
propertyKeys = PropertyDeduplicatorTestUtil.indexPropertyKeys(propertyKeyTokenStore);
propertyStore = neoStores.getPropertyStore();
nodeRecord = getRecord(nodeStore, nodeId);
propertyId = nodeRecord.getNextProp();
indexMock = mock(IndexLookup.Index.class);
when(indexMock.contains(nodeId, indexedValue)).thenReturn(true);
propertyRemoverMock = mock(DuplicatePropertyRemover.class);
}
use of org.neo4j.kernel.impl.store.NeoStores in project neo4j by neo4j.
the class IndexLookupTest method setUp.
@BeforeClass
public static void setUp() {
api = dbRule.getGraphDatabaseAPI();
String notUsedIndexPropKey = "notUsed";
String usedIndexPropKey = "used";
Label usedLabel = Label.label("UsedLabel");
Label notUsedLabel = Label.label("NotUsedLabel");
try (Transaction transaction = api.beginTx()) {
api.schema().indexFor(usedLabel).on(usedIndexPropKey).create();
transaction.success();
}
try (Transaction transaction = api.beginTx()) {
api.schema().awaitIndexesOnline(10, TimeUnit.SECONDS);
indexedNodePropertyValue = "value1";
notIndexedNodePropertyValue = "value2";
Node nodeA = api.createNode(usedLabel);
nodeA.setProperty(usedIndexPropKey, indexedNodePropertyValue);
nodeA.setProperty(notUsedIndexPropKey, notIndexedNodePropertyValue);
indexedNode = nodeA.getId();
Node nodeB = api.createNode(notUsedLabel);
nodeB.setProperty(usedIndexPropKey, notIndexedNodePropertyValue);
nodeB.setProperty(notUsedIndexPropKey, indexedNodePropertyValue);
notIndexedNode = nodeB.getId();
transaction.success();
}
DependencyResolver resolver = api.getDependencyResolver();
NeoStores neoStores = resolver.resolveDependency(RecordStorageEngine.class).testAccessNeoStores();
SchemaStore schemaStore = neoStores.getSchemaStore();
SchemaIndexProvider schemaIndexProvider = resolver.resolveDependency(SchemaIndexProvider.class);
indexLookup = new IndexLookup(schemaStore, schemaIndexProvider);
LabelTokenStore labelTokenStore = neoStores.getLabelTokenStore();
notUsedLabelId = findTokenFor(labelTokenStore, notUsedLabel.name()).id();
usedLabelId = findTokenFor(labelTokenStore, usedLabel.name()).id();
PropertyKeyTokenStore propertyKeyTokenStore = neoStores.getPropertyKeyTokenStore();
notUsedPropertyId = findTokenFor(propertyKeyTokenStore, notUsedIndexPropKey).id();
usedPropertyId = findTokenFor(propertyKeyTokenStore, usedIndexPropKey).id();
}
use of org.neo4j.kernel.impl.store.NeoStores in project neo4j by neo4j.
the class DumpStore method dumpFile.
private static void dumpFile(Function<File, StoreFactory> createStoreFactory, String fileName) throws Exception {
File file = new File(fileName);
// null means all possible ids
long[] ids = null;
if (file.isFile()) {
/* If file exists, even with : in its path, then accept it straight off. */
} else if (!file.isDirectory() && file.getName().indexOf(':') != -1) {
/* Now we know that it is not a directory either, and that the last component
of the path contains a colon, thus it is very likely an attempt to use the
id-specifying syntax. */
int idStart = fileName.lastIndexOf(':');
String[] idStrings = fileName.substring(idStart + 1).split(",");
ids = new long[idStrings.length];
for (int i = 0; i < ids.length; i++) {
ids[i] = Long.parseLong(idStrings[i]);
}
file = new File(fileName.substring(0, idStart));
if (!file.isFile()) {
throw new IllegalArgumentException("No such file: " + fileName);
}
}
StoreType storeType = StoreType.typeOf(file.getName()).orElseThrow(() -> new IllegalArgumentException("Not a store file: " + fileName));
try (NeoStores neoStores = createStoreFactory.apply(file).openNeoStores(storeType)) {
switch(storeType) {
case META_DATA:
dumpMetaDataStore(neoStores);
break;
case NODE:
dumpNodeStore(neoStores, ids);
break;
case RELATIONSHIP:
dumpRelationshipStore(neoStores, ids);
break;
case PROPERTY:
dumpPropertyStore(neoStores, ids);
break;
case SCHEMA:
dumpSchemaStore(neoStores, ids);
break;
case PROPERTY_KEY_TOKEN:
dumpPropertyKeys(neoStores, ids);
break;
case LABEL_TOKEN:
dumpLabels(neoStores, ids);
break;
case RELATIONSHIP_TYPE_TOKEN:
dumpRelationshipTypes(neoStores, ids);
break;
case RELATIONSHIP_GROUP:
dumpRelationshipGroups(neoStores, ids);
break;
default:
throw new IllegalArgumentException("Unsupported store type: " + storeType);
}
}
}
Aggregations