Skip to content

Commit

Permalink
Expose batching labelGetOrCreateForNames via StoreReadLayer.
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisvest committed May 22, 2018
1 parent eac8f5e commit 5187ea9
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 4 deletions.
Expand Up @@ -246,6 +246,28 @@ public int labelGetOrCreateForName( String label ) throws TooManyLabelsException
}
}

@Override
public void labelGetOrCreateForNames( String[] labelNames, int[] labelIds ) throws TooManyLabelsException
{
try
{
labelTokenHolder.getOrCreateIds( labelNames, labelIds );
}
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 )
{
Expand Down
Expand Up @@ -411,6 +411,19 @@ long indexGetCommittedId( SchemaIndexDescriptor index )
*/
int labelGetOrCreateForName( String labelName ) throws TooManyLabelsException;

/**
* Get or create the label token ids for each of the given {@code labelNames}, and store them at the corresponding
* index in the given {@code labelIds} array.
*
* This is effectively a batching version of {@link #labelGetOrCreateForName(String)}.
*
* @param labelNames The array of label names for which to resolve or create their id.
* @param labelIds The array into which the resulting token ids will be stored.
* @throws TooManyLabelsException if too many labels would bve created by this call, compared to the token id space
* available.
*/
void labelGetOrCreateForNames( String[] labelNames, int[] labelIds ) throws TooManyLabelsException;

/**
* Gets relationship type token id for the given {@code relationshipTypeName}, or creates one if there is no
* existing relationship type with the given name.
Expand Down
Expand Up @@ -40,7 +40,7 @@
public class RecordStorageReaderLabelTest extends RecordStorageReaderTestBase
{
@Test
public void should_be_able_to_list_labels_for_node() throws Exception
public void shouldBeAbleToListLabelsForNode() throws Exception
{
// GIVEN
long nodeId;
Expand All @@ -62,7 +62,7 @@ public void should_be_able_to_list_labels_for_node() throws Exception
}

@Test
public void should_be_able_to_get_label_name_for_label() throws Exception
public void shouldBeAbleToGetLabelNameForLabel() throws Exception
{
// GIVEN
String labelName = label1.name();
Expand All @@ -76,7 +76,24 @@ public void should_be_able_to_get_label_name_for_label() throws Exception
}

@Test
public void labels_should_not_leak_out_as_properties()
public void shouldBeAbleToCreateMultipleLabels() throws Exception
{
// GIVEN
String[] labelNames = {label1.name(), label2.name()};
int[] labelIds = new int[labelNames.length];
disk.labelGetOrCreateForNames( labelNames, labelIds );

// WHEN
String firstLabelName = disk.labelGetName( labelIds[0] );
String secondLabelName = disk.labelGetName( labelIds[1] );

// THEN
assertEquals( labelNames[0], firstLabelName );
assertEquals( labelNames[1], secondLabelName );
}

@Test
public void labelsShouldNotLeakOutAsProperties()
{
// GIVEN
Node node = createLabeledNode( db, map( "name", "Node" ), label1 );
Expand All @@ -86,7 +103,7 @@ public void labels_should_not_leak_out_as_properties()
}

@Test
public void should_return_all_nodes_with_label()
public void shouldReturnAllNodesWithLabel()
{
// GIVEN
Node node1 = createLabeledNode( db, map( "name", "First", "age", 1L ), label1 );
Expand Down

0 comments on commit 5187ea9

Please sign in to comment.