How to remove JanusGraph index?
Asked Answered
O

3

5

Index status is installed. How to change the status to registered, then disabled, to remove it?

GraphTraversalSource g = janusGraph.traversal();
JanusGraphManagement janusGraphManagement = janusGraph.openManagement();
JanusGraphIndex phoneIndex = janusGraphManagement.getGraphIndex("phoneIndex");
PropertyKey phone = janusGraphManagement.getPropertyKey("phone");
SchemaStatus indexStatus = phoneIndex.getIndexStatus(phone);
String name = phoneIndex.name();
System.out.println(name);
if (indexStatus == INSTALLED) {
    janusGraphManagement.commit();
    janusGraph.tx().commit();
}

image

Oviform answered 24/7, 2017 at 6:11 Comment(0)
B
4

If you are unable to change the status of index from Install to Enable, I suggest you to check the running instances of JanusGraph and close all the instances except the one with "(Current)" and then try again removing the index.

To check and close instances use following command in gremlin shell:

    mgmt = graph.openManagement()

    mgmt.getOpenInstances() //all open instances

    ==>7f0001016161-dunwich1(current)
    ==>7f0001016161-atlantis1

    mgmt.forceCloseInstance('7f0001016161-atlantis1') //remove an instance
    mgmt.commit()

To remove the index use following code:

   // Disable the "name" composite index
   this.management = this.graph.openManagement()
   def nameIndex = this.management.getGraphIndex(indexName)
   this.management.updateIndex(nameIndex, SchemaAction.DISABLE_INDEX).get()
   this.management.commit()
   this.graph.tx().commit()

   // Block until the SchemaStatus transitions from INSTALLED to REGISTERED
   ManagementSystem.awaitGraphIndexStatus(graph, indexName).status(SchemaStatus.DISABLED).call()
    
   // Delete the index using JanusGraphManagement
   this.management = this.graph.openManagement()
   def delIndex = this.management.getGraphIndex(indexName)
   def future = this.management.updateIndex(delIndex, SchemaAction.REMOVE_INDEX)
   this.management.commit()
   this.graph.tx().commit()

I faced the same issue and tried a lot of other things then finally the above procedure worked!

Brocket answered 14/8, 2017 at 12:19 Comment(1)
Will the method remove index instead of desable it? I want to remove my index to create antother one with the same name, but get error message: "An index with name 'myIndexName' has already been defined"Hudak
C
3

Index has to be disabled first then removed.

    // Disable the "phoneIndex" composite index
    janusGraphManagement = janusGraph.openManagement()
    phoneIndex = janusGraphManagement.getGraphIndex('phoneIndex')
    janusGraphManagement.updateIndex(phoneIndex, SchemaAction.DISABLE_INDEX).get()
    janusGraphManagement.commit()
    janusGraph.tx().commit()
    
    // Block until the SchemaStatus transitions from INSTALLED to REGISTERED
    ManagementSystem.awaitGraphIndexStatus(janusGraph, 'phoneIndex').status(SchemaStatus.DISABLED).call()
    
    // Delete the index using TitanManagement
    janusGraphManagement = janusGraph.openManagement()
    phoneIndex = janusGraphManagement.getGraphIndex('phoneIndex')
    future = janusGraphManagement.updateIndex(phoneIndex, SchemaAction.REMOVE_INDEX)
    janusGraphManagement.commit()
    janusGraph.tx().commit()
Cinquain answered 24/7, 2017 at 6:23 Comment(1)
when I build a index on janusGraph, the index status is install ,it cant turn to enable ,so the index status is installed it cant removeOviform
T
1

Here's a full index-removal example coded in Java (as with your example) and saved to "inmemory" for you.
This way you can see a working example to learn with by changing steps to see what happens.

Code

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.janusgraph.core.JanusGraph;
import org.janusgraph.core.JanusGraphFactory;
import org.janusgraph.core.JanusGraphVertex;
import org.janusgraph.core.PropertyKey;
import org.janusgraph.core.schema.*;
import org.janusgraph.diskstorage.keycolumnvalue.scan.ScanMetrics;
import org.janusgraph.graphdb.database.management.ManagementSystem;

import java.util.concurrent.ExecutionException;

public class Test {
    private static final Logger logger = LogManager.getLogger(Main.class);
    public static void main(String[] args) throws InterruptedException, ExecutionException {
        JanusGraph janusGraph = JanusGraphFactory.build().set("storage.backend", "inmemory").open();
//        JanusGraph janusGraph = JanusGraphFactory.build().set("storage.backend", "cql").set("storage.hostname", "localhost:9042").open();
        GraphTraversalSource g = janusGraph.traversal();
        g.V().drop().iterate();
        janusGraph.tx().commit();
        JanusGraphManagement janusGraphManagement = janusGraph.openManagement();
        PropertyKey propertyKey = janusGraphManagement.getOrCreatePropertyKey("_id");
//        if (!janusGraphManagement.containsGraphIndex("_id"))
        janusGraphManagement.buildIndex("_id", Vertex.class).addKey(propertyKey).buildCompositeIndex();
        janusGraphManagement.commit();
        JanusGraphVertex vertex = janusGraph.addVertex("entity");
        vertex.property("_id", "Test1");
        janusGraph.tx().commit();
        janusGraphManagement = janusGraph.openManagement();
        JanusGraphIndex janusGraphIndex = janusGraphManagement.getGraphIndex("_id");
        logger.info("index.getIndexStatus(propertyKey):\t" + janusGraphIndex.getIndexStatus(propertyKey));
        janusGraphManagement.updateIndex(janusGraphIndex, SchemaAction.DISABLE_INDEX).get();
        logger.info("index.getIndexStatus(propertyKey):\t" + janusGraphIndex.getIndexStatus(propertyKey));
        janusGraphManagement.commit();
        ManagementSystem.awaitGraphIndexStatus(janusGraph, "_id").status(SchemaStatus.DISABLED).call();
        logger.info("index.getIndexStatus(propertyKey):\t" + janusGraphIndex.getIndexStatus(propertyKey));
        janusGraphManagement = janusGraph.openManagement();
        janusGraphIndex = janusGraphManagement.getGraphIndex("_id");
        janusGraphManagement.updateIndex(janusGraphIndex, SchemaAction.DISCARD_INDEX).get();
        logger.info("index.getIndexStatus(propertyKey):\t" + janusGraphIndex.getIndexStatus(propertyKey));
        janusGraphManagement.commit();
        ManagementSystem.awaitGraphIndexStatus(janusGraph, "_id").status(SchemaStatus.DISCARDED).call();
        logger.info("index.getIndexStatus(propertyKey):\t" + janusGraphIndex.getIndexStatus(propertyKey));
        janusGraph.close();
    }
}

Logs

Log4j2 Output should look like

2023-05-16 08:51:40,344 [INFO] [o.j.d.c.b.ReadConfigurationBuilder.main] ::  Set default timestamp provider MICRO
2023-05-16 08:51:40,355 [INFO] [o.j.g.i.UniqueInstanceIdRetriever.main] ::   Generated unique-instance-id=c0a8564911500-rmt-lap-win201
2023-05-16 08:51:40,364 [INFO] [o.j.d.c.ExecutorServiceBuilder.main] ::  Initiated fixed thread pool of size 40
2023-05-16 08:51:40,399 [INFO] [o.j.g.d.StandardJanusGraph.main] ::  Gremlin script evaluation is disabled
2023-05-16 08:51:40,403 [INFO] [o.j.d.l.k.KCVSLog.main] ::   Loaded unidentified ReadMarker start time 2023-05-16T13:51:40.403993Z into org.janusgraph.diskstorage.log.kcvs.KCVSLog$MessagePuller@255990cc
2023-05-16 08:51:40,460 [WARN] [o.j.g.t.StandardJanusGraphTx.main] ::    Query requires iterating over all vertices [[]]. For better performance, use indexes
2023-05-16 08:51:40,791 [INFO] [Main.main] ::    index.getIndexStatus(propertyKey): ENABLED
2023-05-16 08:51:40,801 [INFO] [Main.main] ::    index.getIndexStatus(propertyKey): DISABLED
2023-05-16 08:51:40,919 [INFO] [o.j.g.d.m.GraphIndexStatusWatcher.main] ::   All 1 key(s) on index _id have status(es) [DISABLED]
2023-05-16 08:51:40,919 [INFO] [Main.main] ::    index.getIndexStatus(propertyKey): DISABLED
2023-05-16 08:51:40,952 [INFO] [o.j.g.o.j.IndexRemoveJob.Thread-3] ::    Index _id metrics: success-tx: 4 doc-updates: 0 succeeded: 1
...
2023-05-16 08:51:41,169 [INFO] [o.j.g.d.m.ManagementSystem.Thread-1] ::  Index update job successful for [_id]
2023-05-16 08:51:41,175 [INFO] [Main.main] ::    index.getIndexStatus(propertyKey): DISCARDED
2023-05-16 08:51:41,178 [INFO] [o.j.g.d.m.GraphIndexStatusWatcher.main] ::   All 1 key(s) on index _id have status(es) [DISCARDED]
2023-05-16 08:51:41,178 [INFO] [Main.main] ::    index.getIndexStatus(propertyKey): DISCARDED

Process finished with exit code 0
Thekla answered 16/5, 2023 at 14:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.