- Version:
master (ac0eb23)
- Storage Backend: any
- Mixed Index Backend: elasticsearch
- Expected Behavior:
mgmt.updateIndex(index, SchemaAction.DISCARD_INDEX) on a mixed index deletes the backing Elasticsearch index.
- Current Behavior: for any mixed index whose name contains an uppercase character, it targets an index name that cannot exist, so the data is never deleted.
Details
Every read and write path derives the Elasticsearch index name through generateIndexStoreName, which lowercases the store:
|
* @param config a config passed to ElasticSearchIndex's constructor |
|
* @return a client object open and ready for use |
|
*/ |
private String generateIndexStoreName(String store){
return indexName + INDEX_NAME_SEPARATOR + store.toLowerCase();
}
clearStore composes the same name by hand, and does not:
|
public void clearStore(String indexName, String storeName) throws IOException { |
|
String name = indexName + "_" + storeName; |
|
if (indexExists(name)) { |
|
performRequest(REQUEST_TYPE_DELETE, REQUEST_SEPARATOR + indexName + "_" + storeName, null); |
|
} |
|
} |
public void clearStore(String indexName, String storeName) throws IOException {
String name = indexName + "_" + storeName; // no toLowerCase()
if (indexExists(name)) {
performRequest(REQUEST_TYPE_DELETE, REQUEST_SEPARATOR + indexName + "_" + storeName, null);
}
}
A mixed index's store name is its JanusGraph index name verbatim (createMixedIndex sets INDEXSTORE_NAME = indexName), and index names are case-sensitive on the JanusGraph side. So for mgmt.buildIndex("vertexByName", Vertex.class).buildMixedIndex(...):
|
|
| written and queried as |
<indexName>_vertexbyname |
clearStore targets |
<indexName>_vertexByName |
Since Elasticsearch requires lowercase index names, the second cannot exist. Either indexExists returns false and the call silently no-ops, or ES rejects the invalid name and ManagementSystem reports the misleading "Index removal is not supported for this Backend. Index must be removed in the indexing system directly." Either way the documents remain and the schema is marked DISCARDED, so JanusGraph believes the data is gone.
Related, and worth considering separately: because generateIndexStoreName lowercases, two mixed indexes differing only in case (byName and byname) map to the same Elasticsearch index and silently share documents. ManagementSystem.checkIndexName only enforces uniqueness on the JanusGraph side.
Steps to Reproduce
- Create a mixed index with an uppercase character in its name, e.g.
vertexByName, and index some vertices.
mgmt.updateIndex(mgmt.getGraphIndex("vertexByName"), SchemaAction.DISCARD_INDEX), then commit.
- Observe: the schema status becomes
DISCARDED, and GET _cat/indices still shows <indexName>_vertexbyname with all its documents.
Suggested Fix
String name = indexName + "_" + storeName.toLowerCase();
applied to both the existence check and the delete path. Better still, have ElasticSearchIndex pass the already-derived name so the mapping exists in exactly one place.
master(ac0eb23)mgmt.updateIndex(index, SchemaAction.DISCARD_INDEX)on a mixed index deletes the backing Elasticsearch index.Details
Every read and write path derives the Elasticsearch index name through
generateIndexStoreName, which lowercases the store:janusgraph/janusgraph-es/src/main/java/org/janusgraph/diskstorage/es/ElasticSearchIndex.java
Lines 530 to 532 in ac0eb23
clearStorecomposes the same name by hand, and does not:janusgraph/janusgraph-es/src/main/java/org/janusgraph/diskstorage/es/rest/RestElasticSearchClient.java
Lines 390 to 395 in ac0eb23
A mixed index's store name is its JanusGraph index name verbatim (
createMixedIndexsetsINDEXSTORE_NAME = indexName), and index names are case-sensitive on the JanusGraph side. So formgmt.buildIndex("vertexByName", Vertex.class).buildMixedIndex(...):<indexName>_vertexbynameclearStoretargets<indexName>_vertexByNameSince Elasticsearch requires lowercase index names, the second cannot exist. Either
indexExistsreturns false and the call silently no-ops, or ES rejects the invalid name andManagementSystemreports the misleading"Index removal is not supported for this Backend. Index must be removed in the indexing system directly."Either way the documents remain and the schema is markedDISCARDED, so JanusGraph believes the data is gone.Related, and worth considering separately: because
generateIndexStoreNamelowercases, two mixed indexes differing only in case (byNameandbyname) map to the same Elasticsearch index and silently share documents.ManagementSystem.checkIndexNameonly enforces uniqueness on the JanusGraph side.Steps to Reproduce
vertexByName, and index some vertices.mgmt.updateIndex(mgmt.getGraphIndex("vertexByName"), SchemaAction.DISCARD_INDEX), then commit.DISCARDED, andGET _cat/indicesstill shows<indexName>_vertexbynamewith all its documents.Suggested Fix
applied to both the existence check and the delete path. Better still, have
ElasticSearchIndexpass the already-derived name so the mapping exists in exactly one place.