Skip to content

Commit

Permalink
task indexlabel has conflicts with label index or schema name index
Browse files Browse the repository at this point in the history
fixed: #239

Change-Id: I0b429c00032c0cdf80090b8350be90f6f2b3f74b
  • Loading branch information
zhoney committed Nov 28, 2018
1 parent 455b463 commit cc37f3f
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
import com.baidu.hugegraph.auth.HugeGraphAuthProxy;
import com.baidu.hugegraph.backend.cache.Cache;
import com.baidu.hugegraph.backend.cache.CacheManager;
import com.baidu.hugegraph.backend.store.BackendStoreInfo;
import com.baidu.hugegraph.backend.store.BackendStoreSystemInfo;
import com.baidu.hugegraph.backend.store.memory.InMemoryDBStoreProvider;
import com.baidu.hugegraph.config.HugeConfig;
import com.baidu.hugegraph.config.ServerOptions;
Expand Down Expand Up @@ -193,7 +193,7 @@ private void checkBackendVersionOrExit() {
if (InMemoryDBStoreProvider.matchType(hugegraph.backend())) {
hugegraph.initBackend();
}
BackendStoreInfo info = new BackendStoreInfo(hugegraph);
BackendStoreSystemInfo info = new BackendStoreSystemInfo(hugegraph);
if (!info.exist()) {
LOG.error("The backend store of '{}' has not been initialized",
hugegraph.name());
Expand Down
10 changes: 5 additions & 5 deletions hugegraph-core/src/main/java/com/baidu/hugegraph/HugeGraph.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
import com.baidu.hugegraph.backend.serializer.SerializerFactory;
import com.baidu.hugegraph.backend.store.BackendProviderFactory;
import com.baidu.hugegraph.backend.store.BackendStore;
import com.baidu.hugegraph.backend.store.BackendStoreInfo;
import com.baidu.hugegraph.backend.store.BackendStoreSystemInfo;
import com.baidu.hugegraph.backend.store.BackendStoreProvider;
import com.baidu.hugegraph.backend.tx.GraphTransaction;
import com.baidu.hugegraph.backend.tx.SchemaTransaction;
Expand Down Expand Up @@ -196,7 +196,7 @@ public void initBackend() {
this.loadGraphStore().open(this.configuration);
try {
this.storeProvider.init();
this.initBackendStoreInfo();
this.initBackendStoreSystemInfo();
} finally {
this.loadGraphStore().close();
this.loadSystemStore().close();
Expand Down Expand Up @@ -225,7 +225,7 @@ public void truncateBackend() {
this.waitUntilAllTasksCompleted();

this.storeProvider.truncate();
this.initBackendStoreInfo();
this.initBackendStoreSystemInfo();
}

private void waitUntilAllTasksCompleted() {
Expand All @@ -237,8 +237,8 @@ private void waitUntilAllTasksCompleted() {
}
}

private void initBackendStoreInfo() {
new BackendStoreInfo(this).init();
private void initBackendStoreSystemInfo() {
new BackendStoreSystemInfo(this).init();
}

private SchemaTransaction openSchemaTransaction() throws HugeException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ public void tick() {

if (expireItems > 0) {
LOG.info("Cache expired {} items cost {}ms (size {}, expire {}ms)",
expireItems, now() - current, this.size(), expireTime);
expireItems, now() - current, this.size(), expireTime);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,29 +28,35 @@
import com.baidu.hugegraph.backend.BackendException;
import com.baidu.hugegraph.backend.tx.SchemaTransaction;
import com.baidu.hugegraph.schema.PropertyKey;
import com.baidu.hugegraph.schema.SchemaElement;
import com.baidu.hugegraph.type.HugeType;
import com.baidu.hugegraph.util.E;
import com.baidu.hugegraph.util.Log;

public class BackendStoreInfo {
public class BackendStoreSystemInfo {

private static final Logger LOG = Log.logger(HugeGraph.class);

private static final String PK_BACKEND_INFO = Hidden.hide("backend_info");

private final HugeGraph graph;

public BackendStoreInfo(HugeGraph graph) {
public BackendStoreSystemInfo(HugeGraph graph) {
this.graph = graph;
}

public void init() {
SchemaTransaction schema = this.graph.schemaTransaction();
// Use property key to store backend version
String backendVersion = this.graph.backendVersion();
PropertyKey backendInfo = this.graph.schema()
.propertyKey(PK_BACKEND_INFO)
.userdata("version", backendVersion)
.build();
schema.addPropertyKey(backendInfo);

// Set schema counter if needed
schema.setNextIdLowest(HugeType.SYS_SCHEMA, SchemaElement.MAX_SYS_ID);
}

private Map<String, Object> info() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,23 @@ public void userdata(String key, Object value) {
throw new NotSupportException("user data for index label");
}

public static final IndexLabel VL_IL = new IndexLabel(-1, "~vli");
public static final IndexLabel EL_IL = new IndexLabel(-2, "~eli");

public static final IndexLabel PK_NAME_IL = new IndexLabel(-3, "~pkni");
public static final IndexLabel VL_NAME_IL = new IndexLabel(-4, "~vlni");
public static final IndexLabel EL_NAME_IL = new IndexLabel(-5, "~elni");
public static final IndexLabel IL_NAME_IL = new IndexLabel(-6, "~ilni");
// ABS of System index id must be below SchemaElement.MAX_SYS_ID(32)
private static final int VL_IL_ID = -1;
private static final int EL_IL_ID = -2;
private static final int PKN_IL_ID = -3;
private static final int VLN_IL_ID = -4;
private static final int ELN_IL_ID = -5;
private static final int ILN_IL_ID = -6;

// Label index
static final IndexLabel VL_IL = new IndexLabel(VL_IL_ID, "~vli");
static final IndexLabel EL_IL = new IndexLabel(EL_IL_ID, "~eli");

// Schema name index
static final IndexLabel PKN_IL = new IndexLabel(PKN_IL_ID, "~pkni");
static final IndexLabel VLN_IL = new IndexLabel(VLN_IL_ID, "~vlni");
static final IndexLabel ELN_IL = new IndexLabel(ELN_IL_ID, "~elni");
static final IndexLabel ILN_IL = new IndexLabel(ILN_IL_ID, "~ilni");

public static IndexLabel label(HugeType type) {
switch (type) {
Expand All @@ -145,13 +155,13 @@ public static IndexLabel label(HugeType type) {
case EDGE_IN:
return EL_IL;
case PROPERTY_KEY:
return PK_NAME_IL;
return PKN_IL;
case VERTEX_LABEL:
return VL_NAME_IL;
return VLN_IL;
case EDGE_LABEL:
return EL_NAME_IL;
return ELN_IL;
case INDEX_LABEL:
return IL_NAME_IL;
return ILN_IL;
default:
throw new AssertionError(String.format(
"No primitive index label for '%s'", type));
Expand All @@ -160,20 +170,20 @@ public static IndexLabel label(HugeType type) {

public static IndexLabel label(HugeGraph graph, Id id) {
// Primitive IndexLabel first
if (id.asLong() < 0) {
if (id.asLong() < 0 && id.asLong() > -SchemaElement.MIN_SYS_ID) {
switch ((int) id.asLong()) {
case -1:
case VL_IL_ID:
return VL_IL;
case -2:
case EL_IL_ID:
return EL_IL;
case -3:
return PK_NAME_IL;
case -4:
return VL_NAME_IL;
case -5:
return EL_NAME_IL;
case -6:
return IL_NAME_IL;
case PKN_IL_ID:
return PKN_IL;
case VLN_IL_ID:
return VLN_IL;
case ELN_IL_ID:
return ELN_IL;
case ILN_IL_ID:
return ILN_IL;
default:
throw new AssertionError(String.format(
"No primitive index label for '%s'", id));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@

public abstract class SchemaElement implements Namifiable, Typifiable {

public static final int MAX_SYS_ID = 32;
public static final int MIN_SYS_ID = 7;

protected final HugeGraph graph;

private final Id id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.util.concurrent.Future;
import java.util.concurrent.TimeoutException;

import org.apache.commons.collections.IteratorUtils;
import org.apache.tinkerpop.gremlin.structure.Graph.Hidden;
import org.apache.tinkerpop.gremlin.structure.Vertex;

Expand Down Expand Up @@ -375,8 +376,11 @@ private <V> Iterator<HugeTask<V>> queryTask(Map<String, Object> conditions,
query.limit(limit);
}
Iterator<Vertex> vertices = this.tx().queryVertices(query);
return new MapperIterator<>(vertices, HugeTask::fromVertex);
});
@SuppressWarnings("unchecked")
List<HugeTask<V>> tasks = IteratorUtils.toList(new MapperIterator<>(
vertices, HugeTask::fromVertex));
return tasks;
}).iterator();
}

private <V> V call(Runnable runnable) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

import com.baidu.hugegraph.HugeFactory;
import com.baidu.hugegraph.HugeGraph;
import com.baidu.hugegraph.backend.store.BackendStoreInfo;
import com.baidu.hugegraph.backend.store.BackendStoreSystemInfo;
import com.baidu.hugegraph.config.ServerOptions;
import com.baidu.hugegraph.dist.RegisterUtil;
import com.baidu.hugegraph.util.E;
Expand Down Expand Up @@ -93,7 +93,7 @@ private static void initGraph(String config) throws InterruptedException {
LOG.info("Init graph with config file: {}", config);
HugeGraph graph = HugeFactory.open(config);

BackendStoreInfo backendStoreInfo = new BackendStoreInfo(graph);
BackendStoreSystemInfo backendStoreInfo = new BackendStoreSystemInfo(graph);
try {
if (backendStoreInfo.exist()) {
LOG.info("Skip init-store due to the backend store of '{}' " +
Expand Down

0 comments on commit cc37f3f

Please sign in to comment.