Skip to content

Commit faf50f2

Browse files
author
Alexander Patrikalakis
committed
Make ID store name configurable
1 parent 5bed538 commit faf50f2

9 files changed

Lines changed: 111 additions & 135 deletions

File tree

janusgraph-core/src/main/java/org/janusgraph/diskstorage/Backend.java

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,13 @@ public class Backend implements LockerProvider, AutoCloseable {
8181
* <p/>
8282
* These names are fixed and should NEVER be changed. Changing these strings can
8383
* disrupt storage adapters that rely on these names for specific configurations.
84+
* In the past, the store name for the ID table, janusgraph_ids, was also marked here,
85+
* but to clear the upgrade path from Titan to JanusGraph, we had to pull it into
86+
* configuration.
8487
*/
8588
public static final String EDGESTORE_NAME = "edgestore";
8689
public static final String INDEXSTORE_NAME = "graphindex";
8790

88-
public static final String ID_STORE_NAME = "janusgraph_ids";
89-
9091
public static final String METRICS_STOREMANAGER_NAME = "storeManager";
9192
public static final String METRICS_MERGED_STORE = "stores";
9293
public static final String METRICS_MERGED_CACHE = "caches";
@@ -103,12 +104,6 @@ public class Backend implements LockerProvider, AutoCloseable {
103104

104105
public static final int THREAD_POOL_SIZE_SCALE_FACTOR = 2;
105106

106-
public static final Map<String, Integer> STATIC_KEY_LENGTHS = new HashMap<String, Integer>() {{
107-
put(EDGESTORE_NAME, 8);
108-
put(EDGESTORE_NAME + LOCK_STORE_SUFFIX, 8);
109-
put(ID_STORE_NAME, 8);
110-
}};
111-
112107
private final KeyColumnValueStoreManager storeManager;
113108
private final KeyColumnValueStoreManager storeManagerLocking;
114109
private final StoreFeatures storeFeatures;
@@ -229,7 +224,7 @@ public Locker getLocker(String lockerName) {
229224
public void initialize(Configuration config) {
230225
try {
231226
//EdgeStore & VertexIndexStore
232-
KeyColumnValueStore idStore = storeManager.openDatabase(ID_STORE_NAME);
227+
KeyColumnValueStore idStore = storeManager.openDatabase(config.get(IDS_STORE_NAME));
233228

234229
idAuthority = null;
235230
if (storeFeatures.isKeyConsistent()) {
@@ -414,7 +409,9 @@ public static KeyColumnValueStoreManager getStorageManager(Configuration storage
414409
StoreManager manager = getImplementationClass(storageConfig, storageConfig.get(STORAGE_BACKEND),
415410
StandardStoreManager.getAllManagerClasses());
416411
if (manager instanceof OrderedKeyValueStoreManager) {
417-
manager = new OrderedKeyValueStoreManagerAdapter((OrderedKeyValueStoreManager) manager, STATIC_KEY_LENGTHS);
412+
manager = new OrderedKeyValueStoreManagerAdapter((OrderedKeyValueStoreManager) manager,
413+
ImmutableMap.of(EDGESTORE_NAME, 8, EDGESTORE_NAME + LOCK_STORE_SUFFIX, 8,
414+
storageConfig.get(IDS_STORE_NAME), 8));
418415
}
419416
Preconditions.checkArgument(manager instanceof KeyColumnValueStoreManager,"Invalid storage manager: %s",manager.getClass());
420417
return (KeyColumnValueStoreManager) manager;

janusgraph-core/src/main/java/org/janusgraph/diskstorage/StaticBuffer.java

Lines changed: 28 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -27,76 +27,62 @@
2727
*/
2828
public interface StaticBuffer extends Comparable<StaticBuffer> {
2929

30-
public int length();
30+
int length();
3131

32-
public byte getByte(int position);
32+
byte getByte(int position);
3333

34-
public boolean getBoolean(int position);
34+
boolean getBoolean(int position);
3535

36-
public short getShort(int position);
36+
short getShort(int position);
3737

38-
public int getInt(int position);
38+
int getInt(int position);
3939

40-
public long getLong(int position);
40+
long getLong(int position);
4141

42-
public char getChar(int position);
42+
char getChar(int position);
4343

44-
public float getFloat(int position);
44+
float getFloat(int position);
4545

46-
public double getDouble(int position);
46+
double getDouble(int position);
4747

48-
public byte[] getBytes(int position, int length);
48+
byte[] getBytes(int position, int length);
4949

50-
public short[] getShorts(int position, int length);
50+
short[] getShorts(int position, int length);
5151

52-
public int[] getInts(int position, int length);
52+
int[] getInts(int position, int length);
5353

54-
public long[] getLongs(int position, int length);
54+
long[] getLongs(int position, int length);
5555

56-
public char[] getChars(int position, int length);
56+
char[] getChars(int position, int length);
5757

58-
public float[] getFloats(int position, int length);
58+
float[] getFloats(int position, int length);
5959

60-
public double[] getDoubles(int position, int length);
60+
double[] getDoubles(int position, int length);
6161

62-
public StaticBuffer subrange(int position, int length);
62+
StaticBuffer subrange(int position, int length);
6363

64-
public StaticBuffer subrange(int position, int length, boolean invert);
64+
StaticBuffer subrange(int position, int length, boolean invert);
6565

66-
public ReadBuffer asReadBuffer();
66+
ReadBuffer asReadBuffer();
6767

68-
public<T> T as(Factory<T> factory);
68+
<T> T as(Factory<T> factory);
6969

7070
//Convenience method
71-
public ByteBuffer asByteBuffer();
71+
ByteBuffer asByteBuffer();
7272

73-
public interface Factory<T> {
73+
interface Factory<T> {
7474

75-
public T get(byte[] array, int offset, int limit);
75+
T get(byte[] array, int offset, int limit);
7676

7777
}
7878

79-
public static final Factory<byte[]> ARRAY_FACTORY = new Factory<byte[]>() {
80-
@Override
81-
public byte[] get(byte[] array, int offset, int limit) {
82-
if (offset==0 && limit==array.length) return array;
83-
else return Arrays.copyOfRange(array,offset,limit);
84-
}
85-
79+
Factory<byte[]> ARRAY_FACTORY = (array, offset, limit) -> {
80+
if (offset==0 && limit==array.length) return array;
81+
else return Arrays.copyOfRange(array,offset,limit);
8682
};
8783

88-
public static final Factory<ByteBuffer> BB_FACTORY = new Factory<ByteBuffer>() {
89-
@Override
90-
public ByteBuffer get(byte[] array, int offset, int limit) {
91-
return ByteBuffer.wrap(array, offset, limit - offset);
92-
}
93-
};
84+
Factory<ByteBuffer> BB_FACTORY = (array, offset, limit) -> ByteBuffer.wrap(array, offset, limit - offset);
9485

95-
public static final Factory<StaticBuffer> STATIC_FACTORY = new Factory<StaticBuffer>() {
96-
@Override
97-
public StaticBuffer get(byte[] array, int offset, int limit) {
98-
return new StaticArrayBuffer(array, offset, limit);
99-
}
100-
};
86+
Factory<StaticBuffer> STATIC_FACTORY = (array, offset, limit) -> new StaticArrayBuffer(array, offset, limit);
10187

10288
}

janusgraph-core/src/main/java/org/janusgraph/diskstorage/keycolumnvalue/StoreFeatures.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
package org.janusgraph.diskstorage.keycolumnvalue;
1616

1717
import org.janusgraph.diskstorage.configuration.Configuration;
18+
import org.janusgraph.diskstorage.keycolumnvalue.scan.ScanJob;
1819
import org.janusgraph.diskstorage.util.time.TimestampProviders;
1920

2021
/**
@@ -181,7 +182,7 @@ public interface StoreFeatures {
181182
*
182183
* Backends which don't support the notion of "local" strong consistency may
183184
* return the same configuration returned by
184-
* {@link #getKeyConsistencyTxConfig()}.
185+
* {@link #getKeyConsistentTxConfig()}.
185186
*
186187
* @return a locally (or globally) key-consistent tx config
187188
*/
@@ -213,4 +214,5 @@ public interface StoreFeatures {
213214
* @return
214215
*/
215216
boolean hasOptimisticLocking();
217+
216218
}

janusgraph-core/src/main/java/org/janusgraph/graphdb/configuration/GraphDatabaseConfiguration.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -709,19 +709,29 @@ public boolean apply(@Nullable Integer integer) {
709709
* fraction of the id pool occupied and potentially lost. For write heavy applications, larger block sizes should
710710
* be chosen.
711711
*/
712-
public static final ConfigOption<Integer> IDS_BLOCK_SIZE = new ConfigOption<Integer>(IDS_NS,"block-size",
712+
public static final ConfigOption<Integer> IDS_BLOCK_SIZE = new ConfigOption<>(IDS_NS,"block-size",
713713
"Globally reserve graph element IDs in chunks of this size. Setting this too low will make commits " +
714714
"frequently block on slow reservation requests. Setting it too high will result in IDs wasted when a " +
715715
"graph instance shuts down with reserved but mostly-unused blocks.",
716716
ConfigOption.Type.GLOBAL_OFFLINE, 10000);
717717
// public static final String IDS_BLOCK_SIZE_KEY = "block-size";
718718
// public static final int IDS_BLOCK_SIZE_DEFAULT = 10000;
719719

720+
/**
721+
* The name of the ID store. Currently this defaults to janusgraph_ids. You can override the ID store to
722+
* facilitate migration from JanusGraph's predecessor, Titan. Previously, this KCVStore was named titan_ids.
723+
*/
724+
public static final ConfigOption<String> IDS_STORE_NAME = new ConfigOption<>(IDS_NS, "store-name",
725+
"The name of the ID KCVStore. IDS_STORE_NAME is meant to be used only for backward compatibility with Titan, " +
726+
"and should not be used explicitly in normal operations or in new graphs.",
727+
ConfigOption.Type.GLOBAL_OFFLINE, "janusgraph_ids");
728+
729+
720730
/**
721731
* If flush ids is enabled, vertices and edges are assigned ids immediately upon creation. If not, then ids are only
722732
* assigned when the transaction is committed.
723733
*/
724-
public static final ConfigOption<Boolean> IDS_FLUSH = new ConfigOption<Boolean>(IDS_NS,"flush",
734+
public static final ConfigOption<Boolean> IDS_FLUSH = new ConfigOption<>(IDS_NS,"flush",
725735
"When true, vertices and edges are assigned IDs immediately upon creation. When false, " +
726736
"IDs are assigned only when the transaction commits. Must be disabled for graph partitioning to work.",
727737
ConfigOption.Type.MASKABLE, true);
@@ -744,7 +754,7 @@ public boolean apply(@Nullable Integer integer) {
744754
* of the current block is consumed, a new block will be allocated. Larger values should be used if a lot of ids
745755
* are allocated in a short amount of time. Value must be in (0,1].
746756
*/
747-
public static final ConfigOption<Double> IDS_RENEW_BUFFER_PERCENTAGE = new ConfigOption<Double>(IDS_NS,"renew-percentage",
757+
public static final ConfigOption<Double> IDS_RENEW_BUFFER_PERCENTAGE = new ConfigOption<>(IDS_NS,"renew-percentage",
748758
"When the most-recently-reserved ID block has only this percentage of its total IDs remaining " +
749759
"(expressed as a value between 0 and 1), JanusGraph asynchronously begins reserving another block. " +
750760
"This helps avoid transaction commits waiting on ID reservation even if the block size is relatively small.",

janusgraph-hadoop-parent/janusgraph-hadoop-core/pom.xml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@
3535
<version>${project.version}</version>
3636
<!-- TODO this should be scoped test -->
3737
</dependency>
38+
<dependency>
39+
<groupId>${project.groupId}</groupId>
40+
<artifactId>janusgraph-hbase-core</artifactId>
41+
<version>${project.version}</version>
42+
</dependency>
3843
<dependency>
3944
<groupId>${project.groupId}</groupId>
4045
<artifactId>janusgraph-cassandra</artifactId>
@@ -84,9 +89,6 @@
8489
<goal>testCompile</goal>
8590
-->
8691
</goals>
87-
<configuration>
88-
<providerSelection>1.8</providerSelection>
89-
</configuration>
9092
</execution>
9193
</executions>
9294
</plugin>

janusgraph-hadoop-parent/janusgraph-hadoop-core/src/main/java/org/janusgraph/hadoop/formats/hbase/HBaseBinaryInputFormat.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,15 @@
4242
import java.lang.reflect.Method;
4343
import java.util.List;
4444

45+
import com.google.common.collect.BiMap;
46+
4547
public class HBaseBinaryInputFormat extends AbstractBinaryInputFormat {
4648

4749
private static final Logger log = LoggerFactory.getLogger(HBaseBinaryInputFormat.class);
4850

4951
private final TableInputFormat tableInputFormat = new TableInputFormat();
5052
private RecordReader<ImmutableBytesWritable, Result> tableReader;
51-
private byte[] inputCFBytes;
53+
private byte[] edgeStoreFamily;
5254
private RecordReader<StaticBuffer, Iterable<Entry>> janusgraphRecordReader;
5355

5456
@Override
@@ -60,7 +62,7 @@ public List<InputSplit> getSplits(final JobContext jobContext) throws IOExceptio
6062
public RecordReader<StaticBuffer, Iterable<Entry>> createRecordReader(final InputSplit inputSplit, final TaskAttemptContext taskAttemptContext) throws IOException, InterruptedException {
6163
tableReader = tableInputFormat.createRecordReader(inputSplit, taskAttemptContext);
6264
janusgraphRecordReader =
63-
new HBaseBinaryRecordReader(tableReader, inputCFBytes);
65+
new HBaseBinaryRecordReader(tableReader, edgeStoreFamily);
6466
return janusgraphRecordReader;
6567
}
6668

@@ -82,13 +84,14 @@ public void setConf(final Configuration config) {
8284
// TODO the space-saving short name mapping leaks from HBaseStoreManager here
8385
if (janusgraphConf.get(HBaseStoreManager.SHORT_CF_NAMES)) {
8486
try {
85-
cfName = HBaseStoreManager.shortenCfName(cfName);
87+
final BiMap<String,String> shortCfMap = HBaseStoreManager.createShortCfMap(janusgraphConf);
88+
cfName = HBaseStoreManager.shortenCfName(shortCfMap, cfName);
8689
} catch (PermanentBackendException e) {
8790
throw new RuntimeException(e);
8891
}
8992
}
9093
scanner.addFamily(cfName.getBytes());
91-
inputCFBytes = Bytes.toBytes(cfName);
94+
edgeStoreFamily = Bytes.toBytes(cfName);
9295

9396
//scanner.setFilter(getColumnFilter(janusgraphSetup.inputSlice(this.vertexQuery))); // TODO
9497
//TODO (minor): should we set other options in http://hbase.apache.org/apidocs/org/apache/hadoop/hbase/client/Scan.html for optimization?
@@ -109,7 +112,7 @@ public RecordReader<ImmutableBytesWritable, Result> getTableReader() {
109112
}
110113

111114
public byte[] getEdgeStoreFamily() {
112-
return inputCFBytes;
115+
return edgeStoreFamily;
113116
}
114117

115118
private Filter getColumnFilter(SliceQuery query) {

0 commit comments

Comments
 (0)