-
Notifications
You must be signed in to change notification settings - Fork 2.3k
/
StorageLayer.java
663 lines (592 loc) · 23.9 KB
/
StorageLayer.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
/*
* Copyright (c) 2002-2017 "Neo Technology,"
* Network Engine for Objects in Lund AB [http://neotechnology.com]
*
* This file is part of Neo4j.
*
* Neo4j is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.neo4j.kernel.impl.api.store;
import java.util.Iterator;
import java.util.function.IntPredicate;
import java.util.function.Predicate;
import java.util.function.Supplier;
import org.neo4j.collection.primitive.PrimitiveIntIterator;
import org.neo4j.collection.primitive.PrimitiveIntSet;
import org.neo4j.collection.primitive.PrimitiveLongIterator;
import org.neo4j.cursor.Cursor;
import org.neo4j.graphdb.TransactionFailureException;
import org.neo4j.helpers.collection.Iterators;
import org.neo4j.kernel.api.ReadOperations;
import org.neo4j.kernel.api.constraints.NodePropertyConstraint;
import org.neo4j.kernel.api.constraints.PropertyConstraint;
import org.neo4j.kernel.api.constraints.RelationshipPropertyConstraint;
import org.neo4j.kernel.api.exceptions.EntityNotFoundException;
import org.neo4j.kernel.api.exceptions.LabelNotFoundKernelException;
import org.neo4j.kernel.api.exceptions.PropertyKeyIdNotFoundKernelException;
import org.neo4j.kernel.api.exceptions.RelationshipTypeIdNotFoundKernelException;
import org.neo4j.kernel.api.exceptions.index.IndexNotFoundKernelException;
import org.neo4j.kernel.api.exceptions.schema.SchemaRuleNotFoundException;
import org.neo4j.kernel.api.exceptions.schema.TooManyLabelsException;
import org.neo4j.kernel.api.index.InternalIndexState;
import org.neo4j.kernel.api.properties.PropertyKeyIdIterator;
import org.neo4j.kernel.api.schema_new.LabelSchemaDescriptor;
import org.neo4j.kernel.api.schema_new.RelationTypeSchemaDescriptor;
import org.neo4j.kernel.api.schema_new.index.IndexBoundary;
import org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor;
import org.neo4j.kernel.impl.api.DegreeVisitor;
import org.neo4j.kernel.impl.api.RelationshipVisitor;
import org.neo4j.kernel.impl.api.index.IndexingService;
import org.neo4j.kernel.impl.core.IteratingPropertyReceiver;
import org.neo4j.kernel.impl.core.LabelTokenHolder;
import org.neo4j.kernel.impl.core.PropertyKeyTokenHolder;
import org.neo4j.kernel.impl.core.RelationshipTypeTokenHolder;
import org.neo4j.kernel.impl.core.TokenNotFoundException;
import org.neo4j.kernel.impl.store.InvalidRecordException;
import org.neo4j.kernel.impl.store.NeoStores;
import org.neo4j.kernel.impl.store.NodeStore;
import org.neo4j.kernel.impl.store.RecordCursor;
import org.neo4j.kernel.impl.store.RecordStore;
import org.neo4j.kernel.impl.store.RelationshipStore;
import org.neo4j.kernel.impl.store.SchemaStorage;
import org.neo4j.kernel.impl.store.UnderlyingStorageException;
import org.neo4j.kernel.impl.store.counts.CountsTracker;
import org.neo4j.kernel.impl.store.record.IndexRule;
import org.neo4j.kernel.impl.store.record.RelationshipGroupRecord;
import org.neo4j.kernel.impl.store.record.RelationshipRecord;
import org.neo4j.kernel.impl.transaction.state.PropertyLoader;
import org.neo4j.register.Register;
import org.neo4j.register.Register.DoubleLongRegister;
import org.neo4j.storageengine.api.Direction;
import org.neo4j.storageengine.api.EntityType;
import org.neo4j.storageengine.api.NodeItem;
import org.neo4j.storageengine.api.RelationshipItem;
import org.neo4j.storageengine.api.StorageProperty;
import org.neo4j.storageengine.api.StorageStatement;
import org.neo4j.storageengine.api.StoreReadLayer;
import org.neo4j.storageengine.api.Token;
import org.neo4j.storageengine.api.schema.PopulationProgress;
import org.neo4j.storageengine.api.schema.SchemaRule;
import static org.neo4j.collection.primitive.Primitive.intSet;
import static org.neo4j.function.Predicates.ALWAYS_TRUE_INT;
import static org.neo4j.helpers.collection.Iterables.filter;
import static org.neo4j.kernel.api.schema_new.SchemaDescriptorPredicates.hasLabel;
import static org.neo4j.kernel.impl.api.store.DegreeCounter.countByFirstPrevPointer;
import static org.neo4j.kernel.impl.api.store.DegreeCounter.countRelationshipsInGroup;
import static org.neo4j.kernel.impl.store.record.Record.NO_NEXT_RELATIONSHIP;
import static org.neo4j.kernel.impl.store.record.RecordLoad.CHECK;
import static org.neo4j.kernel.impl.store.record.RecordLoad.FORCE;
import static org.neo4j.register.Registers.newDoubleLongRegister;
/**
* Default implementation of StoreReadLayer. Delegates to NeoStores and indexes.
*/
public class StorageLayer implements StoreReadLayer
{
// These token holders should perhaps move to the cache layer.. not really any reason to have them here?
private final PropertyKeyTokenHolder propertyKeyTokenHolder;
private final LabelTokenHolder labelTokenHolder;
private final RelationshipTypeTokenHolder relationshipTokenHolder;
private final IndexingService indexService;
private final NodeStore nodeStore;
private final RelationshipStore relationshipStore;
private final RecordStore<RelationshipGroupRecord> relationshipGroupStore;
private final SchemaStorage schemaStorage;
private final CountsTracker counts;
private final PropertyLoader propertyLoader;
private final Supplier<StorageStatement> statementProvider;
private final SchemaCache schemaCache;
public StorageLayer( PropertyKeyTokenHolder propertyKeyTokenHolder, LabelTokenHolder labelTokenHolder,
RelationshipTypeTokenHolder relationshipTokenHolder, SchemaStorage schemaStorage, NeoStores neoStores,
IndexingService indexService, Supplier<StorageStatement> storeStatementSupplier, SchemaCache schemaCache )
{
this.relationshipTokenHolder = relationshipTokenHolder;
this.schemaStorage = schemaStorage;
this.indexService = indexService;
this.propertyKeyTokenHolder = propertyKeyTokenHolder;
this.labelTokenHolder = labelTokenHolder;
this.statementProvider = storeStatementSupplier;
this.nodeStore = neoStores.getNodeStore();
this.relationshipStore = neoStores.getRelationshipStore();
this.relationshipGroupStore = neoStores.getRelationshipGroupStore();
this.counts = neoStores.getCounts();
this.propertyLoader = new PropertyLoader( neoStores );
this.schemaCache = schemaCache;
}
@Override
public StorageStatement newStatement()
{
return statementProvider.get();
}
@Override
public int labelGetOrCreateForName( String label ) throws TooManyLabelsException
{
try
{
return labelTokenHolder.getOrCreateId( label );
}
catch ( TransactionFailureException e )
{
// Temporary workaround for the property store based label
// implementation. Actual
// implementation should not depend on internal kernel exception
// messages like this.
if ( e.getCause() instanceof UnderlyingStorageException &&
e.getCause().getMessage().equals( "Id capacity exceeded" ) )
{
throw new TooManyLabelsException( e );
}
throw e;
}
}
@Override
public int labelGetForName( String label )
{
return labelTokenHolder.getIdByName( label );
}
@Override
public String labelGetName( int labelId ) throws LabelNotFoundKernelException
{
try
{
return labelTokenHolder.getTokenById( labelId ).name();
}
catch ( TokenNotFoundException e )
{
throw new LabelNotFoundKernelException( "Label by id " + labelId, e );
}
}
@Override
public PrimitiveLongIterator nodesGetForLabel( StorageStatement statement, int labelId )
{
return statement.getLabelScanReader().nodesWithLabel( labelId );
}
@Override
public NewIndexDescriptor indexGetForLabelAndPropertyKey( LabelSchemaDescriptor descriptor )
{
return schemaCache.indexDescriptor( descriptor );
}
@Override
public Iterator<NewIndexDescriptor> indexesGetForLabel( int labelId )
{
return toIndexDescriptors( filter( rule -> hasLabel( rule, labelId ) && !rule.canSupportUniqueConstraint(),
schemaCache.indexRules() ) );
}
@Override
public Iterator<NewIndexDescriptor> indexesGetAll()
{
return toIndexDescriptors( filter( rule -> !rule.canSupportUniqueConstraint(), schemaCache.indexRules() ) );
}
@Override
public Iterator<NewIndexDescriptor> uniquenessIndexesGetForLabel( int labelId )
{
Predicate<IndexRule> indexRulePredicate =
rule -> hasLabel( rule, labelId ) && rule.canSupportUniqueConstraint();
return toIndexDescriptors( filter( indexRulePredicate, schemaCache.indexRules() ) );
}
@Override
public Iterator<NewIndexDescriptor> uniquenessIndexesGetAll()
{
return toIndexDescriptors( filter( IndexRule::canSupportUniqueConstraint, schemaCache.indexRules() ) );
}
@Override
public Long indexGetOwningUniquenessConstraintId( NewIndexDescriptor index ) throws SchemaRuleNotFoundException
{
IndexRule rule = indexRule( index, NewIndexDescriptor.Filter.ANY );
if ( rule != null )
{
return rule.getOwningConstraint();
}
return null;
}
@Override
public long indexGetCommittedId( NewIndexDescriptor index, NewIndexDescriptor.Filter filter )
throws SchemaRuleNotFoundException
{
IndexRule rule = indexRule( index, filter );
if ( rule == null )
{
throw new SchemaRuleNotFoundException( SchemaRule.Kind.INDEX_RULE, index.schema() );
}
return rule.getId();
}
@Override
public InternalIndexState indexGetState( LabelSchemaDescriptor descriptor ) throws IndexNotFoundKernelException
{
return indexService.getIndexProxy( IndexBoundary.map( descriptor ) ).getState();
}
@Override
public PopulationProgress indexGetPopulationProgress( LabelSchemaDescriptor descriptor )
throws IndexNotFoundKernelException
{
return indexService.getIndexProxy( IndexBoundary.map( descriptor ) ).getIndexPopulationProgress();
}
@Override
public long indexSize( LabelSchemaDescriptor descriptor ) throws IndexNotFoundKernelException
{
Register.DoubleLongRegister result = indexService.indexUpdatesAndSize( IndexBoundary.map( descriptor ) );
return result.readSecond();
}
@Override
public double indexUniqueValuesPercentage( LabelSchemaDescriptor descriptor ) throws IndexNotFoundKernelException
{
return indexService.indexUniqueValuesPercentage( IndexBoundary.map( descriptor ) );
}
@Override
public String indexGetFailure( LabelSchemaDescriptor descriptor ) throws IndexNotFoundKernelException
{
return indexService.getIndexProxy( IndexBoundary.map( descriptor ) ).getPopulationFailure().asString();
}
@Override
public Iterator<NodePropertyConstraint> constraintsGetForLabelAndPropertyKey( LabelSchemaDescriptor descriptor )
{
return schemaCache.constraintsForLabelAndProperty( descriptor );
}
@Override
public Iterator<NodePropertyConstraint> constraintsGetForLabel( int labelId )
{
return schemaCache.constraintsForLabel( labelId );
}
@Override
public Iterator<RelationshipPropertyConstraint> constraintsGetForRelationshipTypeAndPropertyKey(
RelationTypeSchemaDescriptor descriptor )
{
return schemaCache.constraintsForRelationshipTypeAndProperty( descriptor );
}
@Override
public Iterator<RelationshipPropertyConstraint> constraintsGetForRelationshipType( int typeId )
{
return schemaCache.constraintsForRelationshipType( typeId );
}
@Override
public Iterator<PropertyConstraint> constraintsGetAll()
{
return schemaCache.constraints();
}
@Override
public int propertyKeyGetOrCreateForName( String propertyKey )
{
return propertyKeyTokenHolder.getOrCreateId( propertyKey );
}
@Override
public int propertyKeyGetForName( String propertyKey )
{
return propertyKeyTokenHolder.getIdByName( propertyKey );
}
@Override
public String propertyKeyGetName( int propertyKeyId ) throws PropertyKeyIdNotFoundKernelException
{
try
{
return propertyKeyTokenHolder.getTokenById( propertyKeyId ).name();
}
catch ( TokenNotFoundException e )
{
throw new PropertyKeyIdNotFoundKernelException( propertyKeyId, e );
}
}
@Override
public PrimitiveIntIterator graphGetPropertyKeys()
{
return new PropertyKeyIdIterator( propertyLoader.graphLoadProperties( new IteratingPropertyReceiver<>() ) );
}
@Override
public Object graphGetProperty( int propertyKeyId )
{
throw new UnsupportedOperationException();
}
@Override
public Iterator<StorageProperty> graphGetAllProperties()
{
return propertyLoader.graphLoadProperties( new IteratingPropertyReceiver<>() );
}
@Override
public Iterator<Token> propertyKeyGetAllTokens()
{
return propertyKeyTokenHolder.getAllTokens().iterator();
}
@Override
public Iterator<Token> labelsGetAllTokens()
{
return labelTokenHolder.getAllTokens().iterator();
}
@SuppressWarnings( "unchecked" )
@Override
public Iterator<Token> relationshipTypeGetAllTokens()
{
return (Iterator) relationshipTokenHolder.getAllTokens().iterator();
}
@Override
public int relationshipTypeGetForName( String relationshipTypeName )
{
return relationshipTokenHolder.getIdByName( relationshipTypeName );
}
@Override
public String relationshipTypeGetName( int relationshipTypeId ) throws RelationshipTypeIdNotFoundKernelException
{
try
{
return relationshipTokenHolder.getTokenById( relationshipTypeId ).name();
}
catch ( TokenNotFoundException e )
{
throw new RelationshipTypeIdNotFoundKernelException( relationshipTypeId, e );
}
}
@Override
public int relationshipTypeGetOrCreateForName( String relationshipTypeName )
{
return relationshipTokenHolder.getOrCreateId( relationshipTypeName );
}
@Override
public <EXCEPTION extends Exception> void relationshipVisit( long relationshipId,
RelationshipVisitor<EXCEPTION> relationshipVisitor ) throws EntityNotFoundException, EXCEPTION
{
// TODO Please don't create a record for this, it's ridiculous
RelationshipRecord record = relationshipStore.getRecord( relationshipId, relationshipStore.newRecord(), CHECK );
if ( !record.inUse() )
{
throw new EntityNotFoundException( EntityType.RELATIONSHIP, relationshipId );
}
relationshipVisitor.visit( relationshipId, record.getType(), record.getFirstNode(), record.getSecondNode() );
}
@Override
public PrimitiveLongIterator nodesGetAll()
{
return new AllNodeIterator( nodeStore );
}
@Override
public RelationshipIterator relationshipsGetAll()
{
return new AllRelationshipIterator( relationshipStore );
}
@Override
public Cursor<RelationshipItem> nodeGetRelationships( StorageStatement statement, NodeItem nodeItem,
Direction direction )
{
return nodeGetRelationships( statement, nodeItem, direction, ALWAYS_TRUE_INT );
}
@Override
public Cursor<RelationshipItem> nodeGetRelationships( StorageStatement statement, NodeItem node,
Direction direction, IntPredicate relTypes )
{
return statement.acquireNodeRelationshipCursor( node.isDense(), node.id(), node.nextRelationshipId(), direction,
relTypes );
}
@Override
public long reserveNode()
{
return nodeStore.nextId();
}
@Override
public long reserveRelationship()
{
return relationshipStore.nextId();
}
@Override
public void releaseNode( long id )
{
nodeStore.freeId( id );
}
@Override
public void releaseRelationship( long id )
{
relationshipStore.freeId( id );
}
@Override
public long countsForNode( int labelId )
{
return counts.nodeCount( labelId, newDoubleLongRegister() ).readSecond();
}
@Override
public long countsForRelationship( int startLabelId, int typeId, int endLabelId )
{
if ( !(startLabelId == ReadOperations.ANY_LABEL || endLabelId == ReadOperations.ANY_LABEL) )
{
throw new UnsupportedOperationException( "not implemented" );
}
return counts.relationshipCount( startLabelId, typeId, endLabelId, newDoubleLongRegister() ).readSecond();
}
@Override
public long nodesGetCount()
{
return nodeStore.getNumberOfIdsInUse();
}
@Override
public long relationshipsGetCount()
{
return relationshipStore.getNumberOfIdsInUse();
}
@Override
public int labelCount()
{
return labelTokenHolder.size();
}
@Override
public int propertyKeyCount()
{
return propertyKeyTokenHolder.size();
}
@Override
public int relationshipTypeCount()
{
return relationshipTokenHolder.size();
}
@Override
public DoubleLongRegister indexUpdatesAndSize( LabelSchemaDescriptor descriptor, DoubleLongRegister target )
throws IndexNotFoundKernelException
{
return counts.indexUpdatesAndSize( tryGetIndexId( descriptor ), target );
}
@Override
public DoubleLongRegister indexSample( LabelSchemaDescriptor descriptor, DoubleLongRegister target )
throws IndexNotFoundKernelException
{
return counts.indexSample( tryGetIndexId( descriptor ), target );
}
private long tryGetIndexId( LabelSchemaDescriptor descriptor) throws IndexNotFoundKernelException
{
return indexService.getIndexId( IndexBoundary.map( descriptor ) );
}
@Override
public boolean nodeExists( long id )
{
return nodeStore.isInUse( id );
}
@Override
public PrimitiveIntSet relationshipTypes( StorageStatement statement, NodeItem node )
{
PrimitiveIntSet set = intSet();
if ( node.isDense() )
{
RelationshipGroupRecord groupRecord = relationshipGroupStore.newRecord();
RecordCursor<RelationshipGroupRecord> cursor = statement.recordCursors().relationshipGroup();
for ( long id = node.nextGroupId(); id != NO_NEXT_RELATIONSHIP.intValue(); id = groupRecord.getNext() )
{
if ( cursor.next( id, groupRecord, FORCE ) )
{
set.add( groupRecord.getType() );
}
}
}
else
{
nodeGetRelationships( statement, node, Direction.BOTH )
.forAll( relationship -> set.add( relationship.type() ) );
}
return set;
}
@Override
public void degrees( StorageStatement statement, NodeItem nodeItem, DegreeVisitor visitor )
{
if ( nodeItem.isDense() )
{
visitDenseNode( statement, nodeItem, visitor );
}
else
{
visitNode( statement, nodeItem, visitor );
}
}
private IndexRule indexRule( NewIndexDescriptor index, NewIndexDescriptor.Filter filter )
{
for ( IndexRule rule : schemaCache.indexRules() )
{
if ( filter.test( rule.getIndexDescriptor() ) && rule.schema().equals( index.schema() ) )
{
return rule;
}
}
return schemaStorage.indexGetForSchema( index.schema(), filter );
}
@Override
public int degreeRelationshipsInGroup( StorageStatement storeStatement, long nodeId, long groupId,
Direction direction, Integer relType )
{
RelationshipRecord relationshipRecord = relationshipStore.newRecord();
RelationshipGroupRecord relationshipGroupRecord = relationshipGroupStore.newRecord();
return countRelationshipsInGroup( groupId, direction, relType, nodeId, relationshipRecord,
relationshipGroupRecord, storeStatement.recordCursors() );
}
private void visitNode( StorageStatement statement, NodeItem nodeItem, DegreeVisitor visitor )
{
try ( Cursor<RelationshipItem> relationships = nodeGetRelationships( statement, nodeItem, Direction.BOTH ) )
{
while ( relationships.next() )
{
RelationshipItem rel = relationships.get();
int type = rel.type();
switch ( directionOf( nodeItem.id(), rel.id(), rel.startNode(), rel.endNode() ) )
{
case OUTGOING:
visitor.visitDegree( type, 1, 0 );
break;
case INCOMING:
visitor.visitDegree( type, 0, 1 );
break;
case BOTH:
visitor.visitDegree( type, 1, 1 );
break;
default:
throw new IllegalStateException( "You found the missing direction!" );
}
}
}
}
private void visitDenseNode( StorageStatement statement, NodeItem nodeItem, DegreeVisitor visitor )
{
RelationshipGroupRecord relationshipGroupRecord = relationshipGroupStore.newRecord();
RecordCursor<RelationshipGroupRecord> relationshipGroupCursor = statement.recordCursors().relationshipGroup();
RelationshipRecord relationshipRecord = relationshipStore.newRecord();
RecordCursor<RelationshipRecord> relationshipCursor = statement.recordCursors().relationship();
long groupId = nodeItem.nextGroupId();
while ( groupId != NO_NEXT_RELATIONSHIP.longValue() )
{
relationshipGroupCursor.next( groupId, relationshipGroupRecord, FORCE );
if ( relationshipGroupRecord.inUse() )
{
int type = relationshipGroupRecord.getType();
long firstLoop = relationshipGroupRecord.getFirstLoop();
long firstOut = relationshipGroupRecord.getFirstOut();
long firstIn = relationshipGroupRecord.getFirstIn();
long loop = countByFirstPrevPointer( firstLoop, relationshipCursor, nodeItem.id(), relationshipRecord );
long outgoing =
countByFirstPrevPointer( firstOut, relationshipCursor, nodeItem.id(), relationshipRecord ) +
loop;
long incoming =
countByFirstPrevPointer( firstIn, relationshipCursor, nodeItem.id(), relationshipRecord ) +
loop;
visitor.visitDegree( type, outgoing, incoming );
}
groupId = relationshipGroupRecord.getNext();
}
}
private Direction directionOf( long nodeId, long relationshipId, long startNode, long endNode )
{
if ( startNode == nodeId )
{
return endNode == nodeId ? Direction.BOTH : Direction.OUTGOING;
}
if ( endNode == nodeId )
{
return Direction.INCOMING;
}
throw new InvalidRecordException(
"Node " + nodeId + " neither start nor end node of relationship " + relationshipId +
" with startNode:" + startNode + " and endNode:" + endNode );
}
private static Iterator<NewIndexDescriptor> toIndexDescriptors( Iterable<IndexRule> rules )
{
return Iterators.map( IndexRule::getIndexDescriptor, rules.iterator() );
}
}