This is an automated email from the ASF dual-hosted git repository. vgalaxies pushed a commit to branch intro-hstore in repository https://gitbox.apache.org/repos/asf/incubator-hugegraph.git
commit 0cf1cc157cab0ed6b0ff9ccb742377be759e6f53 Author: VGalaxies <[email protected]> AuthorDate: Fri Apr 26 13:49:50 2024 +0800 format hugegraph-hstore --- .../backend/store/hstore/HstoreFeatures.java | 4 +- .../backend/store/hstore/HstoreSessionsImpl.java | 73 +++++++++++----------- .../backend/store/hstore/HstoreStore.java | 55 ++++++++-------- .../backend/store/hstore/HstoreTable.java | 20 +++--- .../backend/store/hstore/HstoreTables.java | 2 + 5 files changed, 78 insertions(+), 76 deletions(-) diff --git a/hugegraph-server/hugegraph-hstore/src/main/java/org/apache/hugegraph/backend/store/hstore/HstoreFeatures.java b/hugegraph-server/hugegraph-hstore/src/main/java/org/apache/hugegraph/backend/store/hstore/HstoreFeatures.java index 3af6f803b..e5aa4b943 100644 --- a/hugegraph-server/hugegraph-hstore/src/main/java/org/apache/hugegraph/backend/store/hstore/HstoreFeatures.java +++ b/hugegraph-server/hugegraph-hstore/src/main/java/org/apache/hugegraph/backend/store/hstore/HstoreFeatures.java @@ -129,5 +129,7 @@ public class HstoreFeatures implements BackendFeatures { } @Override - public boolean supportsTaskAndServerVertex() { return true; } + public boolean supportsTaskAndServerVertex() { + return true; + } } diff --git a/hugegraph-server/hugegraph-hstore/src/main/java/org/apache/hugegraph/backend/store/hstore/HstoreSessionsImpl.java b/hugegraph-server/hugegraph-hstore/src/main/java/org/apache/hugegraph/backend/store/hstore/HstoreSessionsImpl.java index e2ddfd97c..bf45b6800 100755 --- a/hugegraph-server/hugegraph-hstore/src/main/java/org/apache/hugegraph/backend/store/hstore/HstoreSessionsImpl.java +++ b/hugegraph-server/hugegraph-hstore/src/main/java/org/apache/hugegraph/backend/store/hstore/HstoreSessionsImpl.java @@ -61,7 +61,7 @@ import org.apache.hugegraph.util.StringEncoding; public class HstoreSessionsImpl extends HstoreSessions { private static final Set<String> infoInitializedGraph = - Collections.synchronizedSet(new HashSet<>()); + Collections.synchronizedSet(new HashSet<>()); private static int tableCode = 0; private static volatile Boolean initializedNode = Boolean.FALSE; private static volatile PDClient defaultPdClient; @@ -104,11 +104,11 @@ public class HstoreSessionsImpl extends HstoreSessions { synchronized (this) { if (!initializedNode) { PDConfig pdConfig = - PDConfig.of(config.get(CoreOptions.PD_PEERS)) - .setEnableCache(true); + PDConfig.of(config.get(CoreOptions.PD_PEERS)) + .setEnableCache(true); defaultPdClient = PDClient.create(pdConfig); hgStoreClient = - HgStoreClient.create(defaultPdClient); + HgStoreClient.create(defaultPdClient); initializedNode = Boolean.TRUE; } } @@ -121,15 +121,15 @@ public class HstoreSessionsImpl extends HstoreSessions { synchronized (infoInitializedGraph) { if (!infoInitializedGraph.contains(this.graphName)) { Integer partitionCount = - this.config.get(HstoreOptions.PARTITION_COUNT); + this.config.get(HstoreOptions.PARTITION_COUNT); Assert.assertTrue("The value of hstore.partition_count" + " cannot be less than 0.", partitionCount > -1); defaultPdClient.setGraph(Metapb.Graph.newBuilder() .setGraphName( - this.graphName) + this.graphName) .setPartitionCount( - partitionCount) + partitionCount) .build()); infoInitializedGraph.add(this.graphName); } @@ -312,7 +312,6 @@ public class HstoreSessionsImpl extends HstoreSessions { return Session.matchScanType(expected, this.scanType); } - @Override public boolean hasNext() { if (gotNext) { @@ -360,7 +359,7 @@ public class HstoreSessionsImpl extends HstoreSessions { } else { assert this.match(Session.SCAN_ANY) || this.match(Session.SCAN_GT_BEGIN) || this.match( - Session.SCAN_GTE_BEGIN) : "Unknown scan type"; + Session.SCAN_GTE_BEGIN) : "Unknown scan type"; return true; } } @@ -372,8 +371,8 @@ public class HstoreSessionsImpl extends HstoreSessions { throw new NoSuchElementException(); } BackendColumn col = - BackendColumn.of(this.iter.key(), - this.iter.value()); + BackendColumn.of(this.iter.key(), + this.iter.value()); if (this.iter.hasNext()) { gotNext = true; this.iter.next(); @@ -562,7 +561,7 @@ public class HstoreSessionsImpl extends HstoreSessions { @Override public byte[] get(String table, byte[] key) { return this.graph.get(table, HgOwnerKey.of( - HgStoreClientConst.ALL_PARTITION_OWNER, key)); + HgStoreClientConst.ALL_PARTITION_OWNER, key)); } @Override @@ -587,7 +586,7 @@ public class HstoreSessionsImpl extends HstoreSessions { byte[] conditionQueryToByte) { assert !this.hasChanges(); HgKvIterator results = - this.graph.scanIterator(table, conditionQueryToByte); + this.graph.scanIterator(table, conditionQueryToByte); return new ColumnIterator<>(table, results); } @@ -597,8 +596,8 @@ public class HstoreSessionsImpl extends HstoreSessions { assert !this.hasChanges(); HgKvIterator<HgKvEntry> result = this.graph.scanIterator(table, HgOwnerKey.of( - ownerKey, - prefix)); + ownerKey, + prefix)); return new ColumnIterator<>(table, result); } @@ -612,21 +611,21 @@ public class HstoreSessionsImpl extends HstoreSessions { .setQuery(query) .setPerKeyLimit(limit).build(); List<HgKvIterator<HgKvEntry>> scanIterators = - this.graph.scanBatch(scanQuery); + this.graph.scanBatch(scanQuery); LinkedList<BackendColumnIterator> columnIterators = - new LinkedList<>(); + new LinkedList<>(); scanIterators.forEach(item -> { columnIterators.add( - new ColumnIterator<>(table, item)); + new ColumnIterator<>(table, item)); }); return columnIterators; } @Override public BackendEntry.BackendIterator<BackendColumnIterator> scan( - String table, - Iterator<HgOwnerKey> keys, - int scanType, Query queryParam, byte[] query) { + String table, + Iterator<HgOwnerKey> keys, + int scanType, Query queryParam, byte[] query) { ScanOrderType orderType; switch (queryParam.orderType()) { case ORDER_NONE: @@ -685,10 +684,10 @@ public class HstoreSessionsImpl extends HstoreSessions { int scanType) { assert !this.hasChanges(); HgKvIterator result = this.graph.scanIterator(table, HgOwnerKey.of( - ownerKeyFrom, keyFrom), + ownerKeyFrom, keyFrom), HgOwnerKey.of( - ownerKeyTo, - keyTo), 0, + ownerKeyTo, + keyTo), 0, scanType, null); return new ColumnIterator<>(table, result, keyFrom, @@ -703,11 +702,11 @@ public class HstoreSessionsImpl extends HstoreSessions { assert !this.hasChanges(); HgKvIterator<HgKvEntry> result = this.graph.scanIterator(table, HgOwnerKey.of( - ownerKeyFrom, - keyFrom), + ownerKeyFrom, + keyFrom), HgOwnerKey.of( - ownerKeyTo, - keyTo), + ownerKeyTo, + keyTo), 0, scanType, query); @@ -724,11 +723,11 @@ public class HstoreSessionsImpl extends HstoreSessions { assert !this.hasChanges(); HgKvIterator<HgKvEntry> result = this.graph.scanIterator(table, HgOwnerKey.of( - ownerKeyFrom, - keyFrom), + ownerKeyFrom, + keyFrom), HgOwnerKey.of( - ownerKeyTo, - keyTo), + ownerKeyTo, + keyTo), 0, scanType, query); @@ -743,8 +742,8 @@ public class HstoreSessionsImpl extends HstoreSessions { byte[] query) { assert !this.hasChanges(); HgKvIterator<HgKvEntry> iterator = - this.graph.scanIterator(table, codeFrom, codeTo, 256, - new byte[0]); + this.graph.scanIterator(table, codeFrom, codeTo, 256, + new byte[0]); return new ColumnIterator<>(table, iterator, new byte[0], new byte[0], scanType); } @@ -755,8 +754,8 @@ public class HstoreSessionsImpl extends HstoreSessions { byte[] query, byte[] position) { assert !this.hasChanges(); HgKvIterator<HgKvEntry> iterator = - this.graph.scanIterator(table, codeFrom, codeTo, 256, - new byte[0]); + this.graph.scanIterator(table, codeFrom, codeTo, 256, + new byte[0]); iterator.seek(position); return new ColumnIterator<>(table, iterator, new byte[0], new byte[0], scanType); @@ -767,7 +766,7 @@ public class HstoreSessionsImpl extends HstoreSessions { List<HgOwnerKey> keys) { assert !this.hasChanges(); HgKvIterator<HgKvEntry> kvIterator = - this.graph.batchPrefix(table, keys); + this.graph.batchPrefix(table, keys); return new ColumnIterator<>(table, kvIterator); } diff --git a/hugegraph-server/hugegraph-hstore/src/main/java/org/apache/hugegraph/backend/store/hstore/HstoreStore.java b/hugegraph-server/hugegraph-hstore/src/main/java/org/apache/hugegraph/backend/store/hstore/HstoreStore.java index 1127d122e..603ef3a93 100644 --- a/hugegraph-server/hugegraph-hstore/src/main/java/org/apache/hugegraph/backend/store/hstore/HstoreStore.java +++ b/hugegraph-server/hugegraph-hstore/src/main/java/org/apache/hugegraph/backend/store/hstore/HstoreStore.java @@ -67,11 +67,11 @@ public abstract class HstoreStore extends AbstractBackendStore<Session> { private static final Logger LOG = Log.logger(HstoreStore.class); private static final Set<HugeType> INDEX_TYPES = ImmutableSet.of( - HugeType.SECONDARY_INDEX, HugeType.VERTEX_LABEL_INDEX, - HugeType.EDGE_LABEL_INDEX, HugeType.RANGE_INT_INDEX, - HugeType.RANGE_FLOAT_INDEX, HugeType.RANGE_LONG_INDEX, - HugeType.RANGE_DOUBLE_INDEX, HugeType.SEARCH_INDEX, - HugeType.SHARD_INDEX, HugeType.UNIQUE_INDEX + HugeType.SECONDARY_INDEX, HugeType.VERTEX_LABEL_INDEX, + HugeType.EDGE_LABEL_INDEX, HugeType.RANGE_INT_INDEX, + HugeType.RANGE_FLOAT_INDEX, HugeType.RANGE_LONG_INDEX, + HugeType.RANGE_DOUBLE_INDEX, HugeType.SEARCH_INDEX, + HugeType.SHARD_INDEX, HugeType.UNIQUE_INDEX ); private static final BackendFeatures FEATURES = new HstoreFeatures(); @@ -154,7 +154,7 @@ public abstract class HstoreStore extends AbstractBackendStore<Session> { break; default: throw new AssertionError(String.format( - "Invalid type: %s", type)); + "Invalid type: %s", type)); } return this.tables.get((int) table.code()); } @@ -299,8 +299,8 @@ public abstract class HstoreStore extends AbstractBackendStore<Session> { break; default: throw new AssertionError(String.format( - "Unsupported mutate action: %s", - item.action())); + "Unsupported mutate action: %s", + item.action())); } } } @@ -512,8 +512,8 @@ public abstract class HstoreStore extends AbstractBackendStore<Session> { builder.append((table = this.table(type)).table()).append(","); } List<Iterator<BackendEntry>> iteratorList = - table.query(session, queries, - builder.substring(0, builder.length() - 1)); + table.query(session, queries, + builder.substring(0, builder.length() - 1)); for (int i = 0; i < iteratorList.size(); i++) { Iterator<BackendEntry> entries = iteratorList.get(i); // Merge olap results as needed @@ -546,8 +546,8 @@ public abstract class HstoreStore extends AbstractBackendStore<Session> { } Iterator<Iterator<BackendEntry>> iterators = - table.query(session, queries, - builder.substring(0, builder.length() - 1)); + table.query(session, queries, + builder.substring(0, builder.length() - 1)); return iterators; } finally { @@ -556,8 +556,8 @@ public abstract class HstoreStore extends AbstractBackendStore<Session> { } private Iterator<BackendEntry> getBackendEntryIterator( - Iterator<BackendEntry> entries, - Query query) { + Iterator<BackendEntry> entries, + Query query) { HstoreTable table; Set<Id> olapPks = query.olapPks(); if (this.isGraphStore && !olapPks.isEmpty()) { @@ -574,7 +574,6 @@ public abstract class HstoreStore extends AbstractBackendStore<Session> { return entries; } - /** * 重新构造 查询olap表 query * 由于 olap合并成一张表, 在写入olap数据, key在后面增加了pk @@ -598,10 +597,10 @@ public abstract class HstoreStore extends AbstractBackendStore<Session> { // create binary id BytesBuffer buffer = - BytesBuffer.allocate(1 + pk.length() + 1 + id.length()); + BytesBuffer.allocate(1 + pk.length() + 1 + id.length()); buffer.writeId(pk); id = new BinaryBackendEntry.BinaryId( - buffer.writeId(id).bytes(), id); + buffer.writeId(id).bytes(), id); linkedHashSet.add(id); } q.resetIds(); @@ -611,7 +610,7 @@ public abstract class HstoreStore extends AbstractBackendStore<Session> { // create binary id BytesBuffer buffer = BytesBuffer.allocate(1 + pk.length()); pk = new BinaryBackendEntry.BinaryId( - buffer.writeId(pk).bytes(), pk); + buffer.writeId(pk).bytes(), pk); IdPrefixQuery idPrefixQuery = new IdPrefixQuery(HugeType.OLAP, pk); return idPrefixQuery; @@ -708,6 +707,11 @@ public abstract class HstoreStore extends AbstractBackendStore<Session> { this.increaseCounter(type, lowest); } + @Override + public String storedVersion() { + return "1.13"; + } + /***************************** Store defines *****************************/ public static class HstoreSchemaStore extends HstoreStore { @@ -724,13 +728,13 @@ public abstract class HstoreStore extends AbstractBackendStore<Session> { @Override public void increaseCounter(HugeType type, long num) { throw new UnsupportedOperationException( - "HstoreSchemaStore.increaseCounter()"); + "HstoreSchemaStore.increaseCounter()"); } @Override public long getCounter(HugeType type) { throw new UnsupportedOperationException( - "HstoreSchemaStore.getCounter()"); + "HstoreSchemaStore.getCounter()"); } } @@ -764,19 +768,19 @@ public abstract class HstoreStore extends AbstractBackendStore<Session> { @Override public Id nextId(HugeType type) { throw new UnsupportedOperationException( - "HstoreGraphStore.nextId()"); + "HstoreGraphStore.nextId()"); } @Override public void increaseCounter(HugeType type, long num) { throw new UnsupportedOperationException( - "HstoreGraphStore.increaseCounter()"); + "HstoreGraphStore.increaseCounter()"); } @Override public long getCounter(HugeType type) { throw new UnsupportedOperationException( - "HstoreGraphStore.getCounter()"); + "HstoreGraphStore.getCounter()"); } @Override @@ -817,9 +821,4 @@ public abstract class HstoreStore extends AbstractBackendStore<Session> { return super.sessions.existsTable(tableName); } } - - @Override - public String storedVersion() { - return "1.13"; - } } diff --git a/hugegraph-server/hugegraph-hstore/src/main/java/org/apache/hugegraph/backend/store/hstore/HstoreTable.java b/hugegraph-server/hugegraph-hstore/src/main/java/org/apache/hugegraph/backend/store/hstore/HstoreTable.java index 39e24a1d9..de9f74586 100755 --- a/hugegraph-server/hugegraph-hstore/src/main/java/org/apache/hugegraph/backend/store/hstore/HstoreTable.java +++ b/hugegraph-server/hugegraph-hstore/src/main/java/org/apache/hugegraph/backend/store/hstore/HstoreTable.java @@ -72,9 +72,9 @@ public class HstoreTable extends BackendTable<Session, BackendEntry> { Function<BackendEntry, byte[]> ownerDelegate = (entry) -> getOwner(entry); Function<Id, byte[]> ownerByIdDelegate = (id) -> getOwnerId(id); BiFunction<HugeType, Id, byte[]> ownerByQueryDelegate = - (type, id) -> getOwnerId(type, id); + (type, id) -> getOwnerId(type, id); Supplier<byte[]> ownerScanDelegate = - () -> HgStoreClientConst.ALL_PARTITION_OWNER; + () -> HgStoreClientConst.ALL_PARTITION_OWNER; public HstoreTable(String database, String table) { super(String.format("%s+%s", database, table)); @@ -110,7 +110,7 @@ public class HstoreTable extends BackendTable<Session, BackendEntry> { } protected static BackendEntryIterator newEntryIterator( - BackendColumnIterator cols, Query query) { + BackendColumnIterator cols, Query query) { return new BinaryEntryIterator<>(cols, query, (entry, col) -> { if (entry == null || !entry.belongToMe(col)) { HugeType type = query.resultType(); @@ -123,7 +123,7 @@ public class HstoreTable extends BackendTable<Session, BackendEntry> { } protected static BackendEntryIterator newEntryIteratorOlap( - BackendColumnIterator cols, Query query, boolean isOlap) { + BackendColumnIterator cols, Query query, boolean isOlap) { return new BinaryEntryIterator<>(cols, query, (entry, col) -> { if (entry == null || !entry.belongToMe(col)) { HugeType type = query.resultType(); @@ -329,14 +329,14 @@ public class HstoreTable extends BackendTable<Session, BackendEntry> { List<IdPrefixQuery> queries, String tableName) { List<BackendColumnIterator> queryByPrefixList = - this.queryByPrefixList(session, queries, tableName); + this.queryByPrefixList(session, queries, tableName); LinkedList<Iterator<BackendEntry>> iterators = new LinkedList<>(); for (int i = 0; i < queryByPrefixList.size(); i++) { IdPrefixQuery q = queries.get(i).copy(); q.capacity(Query.NO_CAPACITY); q.limit(Query.NO_LIMIT); BackendEntryIterator iterator = - newEntryIterator(queryByPrefixList.get(i), q); + newEntryIterator(queryByPrefixList.get(i), q); iterators.add(iterator); } return iterators; @@ -359,7 +359,7 @@ public class HstoreTable extends BackendTable<Session, BackendEntry> { byte[] queryBytes = originQuery == null ? null : originQuery.bytes(); BackendEntry.BackendIterator<BackendColumnIterator> it - = session.scan(tableName, new Iterator<HgOwnerKey>() { + = session.scan(tableName, new Iterator<HgOwnerKey>() { @Override public boolean hasNext() { if (first[0] != null) { @@ -521,9 +521,9 @@ public class HstoreTable extends BackendTable<Session, BackendEntry> { } protected List<BackendColumnIterator> queryByPrefixList( - Session session, - List<IdPrefixQuery> queries, - String tableName) { + Session session, + List<IdPrefixQuery> queries, + String tableName) { E.checkArgument(queries.size() > 0, "The size of queries must be greater than zero"); IdPrefixQuery query = queries.get(0); diff --git a/hugegraph-server/hugegraph-hstore/src/main/java/org/apache/hugegraph/backend/store/hstore/HstoreTables.java b/hugegraph-server/hugegraph-hstore/src/main/java/org/apache/hugegraph/backend/store/hstore/HstoreTables.java index f4ebf7ebe..704204670 100644 --- a/hugegraph-server/hugegraph-hstore/src/main/java/org/apache/hugegraph/backend/store/hstore/HstoreTables.java +++ b/hugegraph-server/hugegraph-hstore/src/main/java/org/apache/hugegraph/backend/store/hstore/HstoreTables.java @@ -52,6 +52,7 @@ public class HstoreTables { * task信息存储表 */ public static class TaskInfo extends HstoreTable { + public static final String TABLE = HugeTableType.TASK_INFO_TABLE.string(); public TaskInfo(String database) { @@ -65,6 +66,7 @@ public class HstoreTables { } public static class ServerInfo extends HstoreTable { + public static final String TABLE = HugeTableType.SERVER_INFO_TABLE.string(); public ServerInfo(String database) {
