Search in sources :

Example 1 with TinkerMaxGraph

use of com.alibaba.maxgraph.structure.graph.TinkerMaxGraph in project GraphScope by alibaba.

the class Frontend method initAndStartGremlinServer.

@Override
protected void initAndStartGremlinServer() throws Exception {
    SchemaFetcher schemaFetcher;
    String vineyardSchemaPath = this.instanceConfig.getVineyardSchemaPath();
    logger.info("Read schema from vineyard schema file " + vineyardSchemaPath);
    schemaFetcher = new JsonFileSchemaFetcher(vineyardSchemaPath);
    this.remoteGraph = new RemoteGraph(this, schemaFetcher);
    this.remoteGraph.refresh();
    this.graph = new TinkerMaxGraph(instanceConfig, remoteGraph, new DefaultGraphDfs());
    // add gaia compiler
    AsyncRpcChannelFetcher gaiaRpcFetcher = new AddressChannelFetcher(new ExecutorAddressFetcher(this.clientManager));
    GraphStoreService gaiaStoreService = new VineyardGraphStore(schemaFetcher);
    AbstractBroadcastProcessor broadcastProcessor = new AsyncRpcBroadcastProcessor(gaiaRpcFetcher);
    gaiaGraphServer = new GaiaGraphServer(this.graph, instanceConfig, gaiaStoreService, broadcastProcessor, new VineyardConfig(instanceConfig));
    gaiaGraphServer.start(0, null, false);
    this.gremlinServerPort = gaiaGraphServer.getGremlinServerPort();
}
Also used : SchemaFetcher(com.alibaba.maxgraph.compiler.api.schema.SchemaFetcher) JsonFileSchemaFetcher(com.alibaba.maxgraph.compiler.schema.JsonFileSchemaFetcher) RemoteGraph(com.alibaba.maxgraph.frontendservice.RemoteGraph) AbstractBroadcastProcessor(com.alibaba.graphscope.gaia.broadcast.AbstractBroadcastProcessor) AsyncRpcChannelFetcher(com.alibaba.graphscope.gaia.broadcast.channel.AsyncRpcChannelFetcher) ExecutorAddressFetcher(com.alibaba.maxgraph.frontendservice.server.ExecutorAddressFetcher) DefaultGraphDfs(com.alibaba.maxgraph.compiler.dfs.DefaultGraphDfs) AsyncRpcBroadcastProcessor(com.alibaba.graphscope.gaia.broadcast.AsyncRpcBroadcastProcessor) JsonFileSchemaFetcher(com.alibaba.maxgraph.compiler.schema.JsonFileSchemaFetcher) TinkerMaxGraph(com.alibaba.maxgraph.structure.graph.TinkerMaxGraph) GraphStoreService(com.alibaba.graphscope.gaia.store.GraphStoreService)

Example 2 with TinkerMaxGraph

use of com.alibaba.maxgraph.structure.graph.TinkerMaxGraph in project GraphScope by alibaba.

the class Frontend method initAndStartGremlinServer.

protected void initAndStartGremlinServer() throws Exception {
    SchemaFetcher schemaFetcher;
    String vineyardSchemaPath = this.instanceConfig.getVineyardSchemaPath();
    LOG.info("Read schema from vineyard schema file " + vineyardSchemaPath);
    schemaFetcher = new JsonFileSchemaFetcher(vineyardSchemaPath);
    this.remoteGraph = new RemoteGraph(this, schemaFetcher);
    this.remoteGraph.refresh();
    this.graph = new TinkerMaxGraph(instanceConfig, remoteGraph, new DefaultGraphDfs());
    this.graphGremlinServer = new MaxGraphServer(this.graph);
    int tmpGremlinServerPort = instanceConfig.getGremlinServerPort() > 0 ? instanceConfig.getGremlinServerPort() : 0;
    ProcessorLoader processorLoader;
    switch(instanceConfig.getGremlinServerMode()) {
        case TIMELY:
        case MIXED:
            {
                processorLoader = MixedProcessorLoader.newProcessorLoader(graph, this.instanceConfig, new ExecutorAddressFetcher(clientManager), schemaFetcher, new ZKStatementStore(instanceConfig), new MaxGraphRecordProcessorManager(this.graph, this), this.getFrontendQueryManager());
                break;
            }
        default:
            {
                processorLoader = GremlinProcessorLoader.newProcessorLoader();
                break;
            }
    }
    this.graphGremlinServer.start(tmpGremlinServerPort, processorLoader, instanceConfig.getInstanceAuthType() == 1);
    this.gremlinServerPort = tmpGremlinServerPort > 0 ? tmpGremlinServerPort : this.graphGremlinServer.getGremlinServerPort();
    LOG.info("gremlin server port:{}", this.gremlinServerPort);
}
Also used : ZKStatementStore(com.alibaba.maxgraph.frontendservice.query.ZKStatementStore) JsonFileSchemaFetcher(com.alibaba.maxgraph.compiler.schema.JsonFileSchemaFetcher) SchemaFetcher(com.alibaba.maxgraph.compiler.api.schema.SchemaFetcher) JsonFileSchemaFetcher(com.alibaba.maxgraph.compiler.schema.JsonFileSchemaFetcher) TinkerMaxGraph(com.alibaba.maxgraph.structure.graph.TinkerMaxGraph) MixedProcessorLoader(com.alibaba.maxgraph.server.processor.MixedProcessorLoader) GremlinProcessorLoader(com.alibaba.maxgraph.server.GremlinProcessorLoader) ProcessorLoader(com.alibaba.maxgraph.server.ProcessorLoader) MaxGraphRecordProcessorManager(com.alibaba.maxgraph.frontendservice.server.manager.MaxGraphRecordProcessorManager) ExecutorAddressFetcher(com.alibaba.maxgraph.frontendservice.server.ExecutorAddressFetcher) MaxGraphServer(com.alibaba.maxgraph.server.MaxGraphServer) Endpoint(com.alibaba.maxgraph.sdkcommon.client.Endpoint) DefaultGraphDfs(com.alibaba.maxgraph.compiler.dfs.DefaultGraphDfs)

Example 3 with TinkerMaxGraph

use of com.alibaba.maxgraph.structure.graph.TinkerMaxGraph in project GraphScope by alibaba.

the class MxVertexProperty method remove.

@Override
public void remove() {
    TinkerMaxGraph tinkerMaxGraph = (TinkerMaxGraph) vertex.graph();
    GraphVertex graphVertex = (GraphVertex) tinkerMaxGraph.schema().getElement(vertex.label());
    Set<String> propNameList = graphVertex.getPrimaryKeyList().stream().map(GraphProperty::getName).collect(Collectors.toSet());
    if (propNameList.contains(this.key)) {
        return;
    }
    Iterator<VertexProperty<Object>> propItor = vertex.properties();
    Map<String, Object> kvs = Maps.newHashMap();
    while (propItor.hasNext()) {
        VertexProperty<Object> prop = propItor.next();
        kvs.put(prop.key(), prop.value());
    }
    kvs.remove(this.key);
    tinkerMaxGraph.getBaseGraph().addVertex(vertex.label(), kvs);
}
Also used : GraphVertex(com.alibaba.maxgraph.compiler.api.schema.GraphVertex) TinkerMaxGraph(com.alibaba.maxgraph.structure.graph.TinkerMaxGraph) VertexProperty(org.apache.tinkerpop.gremlin.structure.VertexProperty)

Example 4 with TinkerMaxGraph

use of com.alibaba.maxgraph.structure.graph.TinkerMaxGraph in project GraphScope by alibaba.

the class MaxGraphGryoReader method readGraph.

/**
 * Read data into a {@link Graph} from output generated by any of the {@link GryoWriter} {@code writeVertex} or
 * {@code writeVertices} methods or by {@link GryoWriter#writeGraph(OutputStream, Graph)}.
 *
 * @param inputStream    a stream containing an entire graph of vertices and edges as defined by the accompanying
 *                       {@link GraphWriter#writeGraph(OutputStream, Graph)}.
 * @param graphToWriteTo the graph to write to when reading from the stream.
 * @throws IOException
 */
@Override
public void readGraph(final InputStream inputStream, final Graph graphToWriteTo) throws IOException {
    if (!(graphToWriteTo instanceof TinkerMaxGraph)) {
        throw new IOException("Only support snapshot maxgraph here.");
    }
    TinkerMaxGraph tinkerMaxGraph = (TinkerMaxGraph) graphToWriteTo;
    Transaction tx = tinkerMaxGraph.tx();
    tx.open();
    Input input = new Input(inputStream);
    // insert all vertices
    List<StarGraph.StarVertex> starVertexList = Lists.newArrayList();
    while (!input.eof()) {
        readHeader(input);
        final StarGraph starGraph = kryo.readObject(input, StarGraph.class);
        // read the terminator
        kryo.readClassAndObject(input);
        StarGraph.StarVertex starVertex = starGraph.getStarVertex();
        Iterator<VertexProperty<Object>> propertyIterator = starVertex.properties();
        List<Object> keyValues = Lists.newArrayList();
        keyValues.add(T.label);
        keyValues.add(starVertex.label());
        keyValues.add("id");
        keyValues.add(Long.parseLong(starVertex.id().toString()));
        while (propertyIterator.hasNext()) {
            VertexProperty<Object> vertexProperty = propertyIterator.next();
            keyValues.add(vertexProperty.key());
            keyValues.add(vertexProperty.value());
        }
        tinkerMaxGraph.addVertexAsync(keyValues.toArray());
        starVertexList.add(starVertex);
    }
    tx.commit();
    // query the inserted vertices
    Iterator<Vertex> vertexIterator = graphToWriteTo.vertices();
    Map<Integer, Vertex> insertedVertexMap = Maps.newHashMap();
    while (vertexIterator.hasNext()) {
        Vertex vertex = vertexIterator.next();
        insertedVertexMap.put(((Long) vertex.property("id").value()).intValue(), vertex);
    }
    // insert all the edges
    for (StarGraph.StarVertex starVertex : starVertexList) {
        Iterator<Edge> edgeIterator = starVertex.edges(Direction.OUT);
        while (edgeIterator.hasNext()) {
            Edge edge = edgeIterator.next();
            Vertex srcVertex = edge.outVertex();
            Vertex dstVertex = edge.inVertex();
            Vertex insertedSrcVertex = insertedVertexMap.get(srcVertex.id());
            Vertex insertedDstVertex = insertedVertexMap.get(dstVertex.id());
            checkNotNull(insertedSrcVertex, "src vertex cant be null for edge " + edge);
            checkNotNull(insertedDstVertex, "dst vertex cant be null for edge " + edge);
            List<Object> keyValues = Lists.newArrayList();
            Iterator<Property<Object>> propertyIterator = edge.properties();
            keyValues.add("id");
            keyValues.add(edge.id());
            while (propertyIterator.hasNext()) {
                Property<Object> property = propertyIterator.next();
                keyValues.add(property.key());
                keyValues.add(property.value());
            }
            tinkerMaxGraph.addEdgeAsync(insertedSrcVertex, insertedDstVertex, edge.label(), keyValues.toArray());
        }
    }
    tx.commit();
}
Also used : StarGraph(org.apache.tinkerpop.gremlin.structure.util.star.StarGraph) IOException(java.io.IOException) Input(org.apache.tinkerpop.shaded.kryo.io.Input) TinkerMaxGraph(com.alibaba.maxgraph.structure.graph.TinkerMaxGraph) DetachedVertexProperty(org.apache.tinkerpop.gremlin.structure.util.detached.DetachedVertexProperty) DetachedEdge(org.apache.tinkerpop.gremlin.structure.util.detached.DetachedEdge) DetachedVertexProperty(org.apache.tinkerpop.gremlin.structure.util.detached.DetachedVertexProperty) DetachedProperty(org.apache.tinkerpop.gremlin.structure.util.detached.DetachedProperty)

Example 5 with TinkerMaxGraph

use of com.alibaba.maxgraph.structure.graph.TinkerMaxGraph in project GraphScope by alibaba.

the class Frontend method initAndStartGremlinServer.

@Override
protected void initAndStartGremlinServer() throws Exception {
    SchemaFetcher schemaFetcher;
    String vineyardSchemaPath = this.instanceConfig.getVineyardSchemaPath();
    logger.info("Read schema from vineyard schema file " + vineyardSchemaPath);
    schemaFetcher = new JsonFileSchemaFetcher(vineyardSchemaPath);
    this.remoteGraph = new RemoteGraph(this, schemaFetcher);
    this.remoteGraph.refresh();
    this.graph = new TinkerMaxGraph(instanceConfig, remoteGraph, new DefaultGraphDfs());
    // add ir compiler
    Configs configs = getConfigs(this.instanceConfig);
    IrMetaFetcher irMetaFetcher = getStoreConfigs(this.instanceConfig);
    RpcAddressFetcher addressFetcher = new ExecutorAddressFetcher(this.clientManager);
    RpcChannelFetcher channelFetcher = new RpcAddressChannelFetcher(addressFetcher);
    this.gremlinServer = new IrGremlinServer(this.instanceConfig.getGremlinServerPort());
    this.gremlinServer.start(configs, irMetaFetcher, channelFetcher, new IrMetaQueryCallback(irMetaFetcher), TestGraphFactory.VINEYARD);
    this.gremlinServerPort = gremlinServer.getGremlinServerPort();
}
Also used : SchemaFetcher(com.alibaba.maxgraph.compiler.api.schema.SchemaFetcher) JsonFileSchemaFetcher(com.alibaba.maxgraph.compiler.schema.JsonFileSchemaFetcher) RemoteGraph(com.alibaba.maxgraph.frontendservice.RemoteGraph) ExecutorAddressFetcher(com.alibaba.maxgraph.frontendservice.server.ExecutorAddressFetcher) IrGremlinServer(com.alibaba.graphscope.gremlin.service.IrGremlinServer) DefaultGraphDfs(com.alibaba.maxgraph.compiler.dfs.DefaultGraphDfs) RpcChannelFetcher(com.alibaba.graphscope.common.client.RpcChannelFetcher) JsonFileSchemaFetcher(com.alibaba.maxgraph.compiler.schema.JsonFileSchemaFetcher) RpcAddressFetcher(com.alibaba.maxgraph.common.rpc.RpcAddressFetcher) TinkerMaxGraph(com.alibaba.maxgraph.structure.graph.TinkerMaxGraph) IrMetaFetcher(com.alibaba.graphscope.common.store.IrMetaFetcher) IrMetaQueryCallback(com.alibaba.graphscope.common.manager.IrMetaQueryCallback) Configs(com.alibaba.graphscope.common.config.Configs)

Aggregations

TinkerMaxGraph (com.alibaba.maxgraph.structure.graph.TinkerMaxGraph)7 DefaultGraphDfs (com.alibaba.maxgraph.compiler.dfs.DefaultGraphDfs)4 SchemaFetcher (com.alibaba.maxgraph.compiler.api.schema.SchemaFetcher)3 JsonFileSchemaFetcher (com.alibaba.maxgraph.compiler.schema.JsonFileSchemaFetcher)3 ExecutorAddressFetcher (com.alibaba.maxgraph.frontendservice.server.ExecutorAddressFetcher)3 RemoteGraph (com.alibaba.maxgraph.frontendservice.RemoteGraph)2 RpcChannelFetcher (com.alibaba.graphscope.common.client.RpcChannelFetcher)1 Configs (com.alibaba.graphscope.common.config.Configs)1 IrMetaQueryCallback (com.alibaba.graphscope.common.manager.IrMetaQueryCallback)1 IrMetaFetcher (com.alibaba.graphscope.common.store.IrMetaFetcher)1 AbstractBroadcastProcessor (com.alibaba.graphscope.gaia.broadcast.AbstractBroadcastProcessor)1 AsyncRpcBroadcastProcessor (com.alibaba.graphscope.gaia.broadcast.AsyncRpcBroadcastProcessor)1 AsyncRpcChannelFetcher (com.alibaba.graphscope.gaia.broadcast.channel.AsyncRpcChannelFetcher)1 GraphStoreService (com.alibaba.graphscope.gaia.store.GraphStoreService)1 IrGremlinServer (com.alibaba.graphscope.gremlin.service.IrGremlinServer)1 InstanceConfig (com.alibaba.maxgraph.common.cluster.InstanceConfig)1 RpcAddressFetcher (com.alibaba.maxgraph.common.rpc.RpcAddressFetcher)1 GraphElement (com.alibaba.maxgraph.compiler.api.schema.GraphElement)1 GraphSchema (com.alibaba.maxgraph.compiler.api.schema.GraphSchema)1 GraphVertex (com.alibaba.maxgraph.compiler.api.schema.GraphVertex)1