2016-11-22 4 views
1

クエリのパフォーマンスをテストするために、Titan 1.0.0の単一インスタンスにmoderate graphを設定しています。私はストレージバックエンドとしてCassandra 2.0.17を使用しています。Cassandraストレージバックエンドのタイタンインデックスの問題

ノードインデックスを作成できないため、結果が最適にクエリできません。私はdocsを読んでいます。私は、スキーマ定義、データ母集団とインデックス作成のために、次のGroovyスクリプトを使用しています:

import com.thinkaurelius.titan.core.*; 
import com.thinkaurelius.titan.core.schema.*; 
import com.thinkaurelius.titan.graphdb.database.management.ManagementSystem; 
import java.time.temporal.ChronoUnit; 

graph = TitanFactory.open('conf/my-titan.properties'); 
mgmt = graph.openManagement(); 

// Build graph schema 
//  Node properties 
idProp = mgmt.containsPropertyKey('userId') ? 
    mgmt.getPropertyKey('userId') : mgmt.makePropertyKey('id').dataType(String.class).cardinality(Cardinality.SINGLE); 
isPublicProp = mgmt.containsPropertyKey('isPublic') ? 
    mgmt.getPropertyKey('isPublic') : mgmt.makePropertyKey('isPublic').dataType(Boolean.class).cardinality(Cardinality.SINGLE); 
completionPercentageProp = mgmt.containsPropertyKey('completionPercentage') ? 
    mgmt.getPropertyKey('completionPercentage') : mgmt.makePropertyKey('completionPercentage').dataType(Integer.class).cardinality(Cardinality.SINGLE); 
genderProp = mgmt.containsPropertyKey('gender') ? 
mgmt.getPropertyKey('gender') : mgmt.makePropertyKey('gender').dataType(String.class).cardinality(Cardinality.SINGLE); 
regionProp = mgmt.containsPropertyKey('region') ? 
mgmt.getPropertyKey('region') : mgmt.makePropertyKey('region').dataType(String.class).cardinality(Cardinality.SINGLE); 
lastLoginProp = mgmt.containsPropertyKey('lastLogin') ? 
mgmt.getPropertyKey('lastLogin') : mgmt.makePropertyKey('lastLogin').dataType(String.class).cardinality(Cardinality.SINGLE); 
registrationProp = mgmt.containsPropertyKey('registration') ? 
mgmt.getPropertyKey('registration') : mgmt.makePropertyKey('registration').dataType(String.class).cardinality(Cardinality.SINGLE); 
ageProp = mgmt.containsPropertyKey('age') ? mgmt.getPropertyKey('age') : mgmt.makePropertyKey('age').dataType(Integer.class).cardinality(Cardinality.SINGLE); 
mgmt.commit(); 

nUsers = 0 
println 'Starting nodes population...'; 
// Load users 
new File('/home/jarandaf/soc-pokec-profiles.txt').eachLine { 
    try { 
    fields = it.split('\t').take(8); 
    userId = fields[0]; 
    isPublic = fields[1] == '1' ? true : false; 
    completionPercentage = fields[2] 
    gender = fields[3] == '1' ? 'male' : 'female'; 
    region = fields[4]; 
    lastLogin = fields[5]; 
    registration = fields[6]; 
    age = fields[7] as int; 
    graph.addVertex('userId', userId, 'isPublic', isPublic, 'completionPercentage', completionPercentage, 'gender', gender, 'region', region, 'lastLogin', lastLogin, 'registration', registration, 'age', age); 
    } catch (Exception e) { 
    // Silently skip... 
    } 
    nUsers += 1 
    if (nUsers % 100000 == 0) println String.valueOf(nUsers) + ' loaded...'; 
}; 
graph.tx().commit(); 
println 'Nodes population finished'; 

// Index users by userId, gender and age 
println 'Getting node properties...'; 
mgmt = graph.openManagement(); 
userId = mgmt.getPropertyKey('userId'); 
gender = mgmt.getPropertyKey('gender'); 
age = mgmt.getPropertyKey('age'); 

println 'Building byUserId index...'; 
if (mgmt.getGraphIndex('byUserId') == null) mgmt.buildIndex('byUserId', Vertex.class).addKey(userId).buildCompositeIndex(); 
println 'Building byGender index...'; 
if (mgmt.getGraphIndex('byGender') == null) mgmt.buildIndex('byGender', Vertex.class).addKey(gender).buildCompositeIndex(); 
println 'Building byAge index...'; 
if (mgmt.getGraphIndex('byAge') == null) mgmt.buildIndex('byAge', Vertex.class).addKey(age).buildCompositeIndex(); 
mgmt.commit(); 

// Wait for the indexes to become available 
println 'Awaiting byUserId graph index status...'; 
ManagementSystem.awaitGraphIndexStatus(graph, 'byUserId') 
    .status(SchemaStatus.REGISTERED) 
    .timeout(10, ChronoUnit.MINUTES) 
    .call(); 
println 'Awaiting byGender graph index status...'; 
ManagementSystem.awaitGraphIndexStatus(graph, 'byGender') 
    .status(SchemaStatus.REGISTERED) 
    .timeout(10, ChronoUnit.MINUTES) 
    .call(); 

println 'Awaiting byAge graph index status...'; 
ManagementSystem.awaitGraphIndexStatus(graph, 'byAge') 
    .status(SchemaStatus.REGISTERED) 
    .timeout(10, ChronoUnit.MINUTES) 
    .call(); 

// Reindex the existing data 
mgmt = graph.openManagement(); 
println 'Reindexing data by byUserId index...'; 
mgmt.updateIndex(mgmt.getGraphIndex('byUserId'), SchemaAction.REINDEX).get(); 
println 'Reindexing data by byGender index...'; 
mgmt.updateIndex(mgmt.getGraphIndex('byGender'), SchemaAction.REINDEX).get(); 
println 'Reindexing data by byAge index...'; 
mgmt.updateIndex(mgmt.getGraphIndex('byAge'), SchemaAction.REINDEX).get(); 
mgmt.commit(); 

// Enable indexes 
println 'Enabling byUserId index...' 
mgmt.awaitGraphIndexStatus(graph, 'byUserId').status(SchemaStatus.ENABLED).call(); 
println 'Enabling byGender index...' 
mgmt.awaitGraphIndexStatus(graph, 'byGender').status(SchemaStatus.ENABLED).call(); 
println 'Enabling byAge index...' 
mgmt.awaitGraphIndexStatus(graph, 'byAge').status(SchemaStatus.ENABLED).call(); 

graph.close(); 

私は取得していますエラーには、次のされており、REINDEX相と関連している:

08:24:26 ERROR com.thinkaurelius.titan.graphdb.database.management.ManagementLogger - Evicted [[email protected]] from cache but waiting too long for transactions to close. Stale transaction alert on: [standardtitantx[0x4b8696a4], standardtitantx[0x2d39f30a], standardtitantx[0x0da9172d], standardtitantx[0x7c6c7909], standardtitantx[0x79dd0a38], standardtitantx[0x5999c49e], standardtitantx[0x5aaba4a7]] 
08:24:26 ERROR com.thinkaurelius.titan.graphdb.database.management.ManagementLogger - Evicted [[email protected]] from cache but waiting too long for transactions to close. Stale transaction alert on: [standardtitantx[0x4b8696a4], standardtitantx[0x2d39f30a], standardtitantx[0x0da9172d], standardtitantx[0x7c6c7909], standardtitantx[0x79dd0a38], standardtitantx[0x5999c49e], standardtitantx[0x5aaba4a7]] 
08:24:26 ERROR com.thinkaurelius.titan.graphdb.database.management.ManagementLogger - Evicted [[email protected]] from cache but waiting too long for transactions to close. Stale transaction alert on: [standardtitantx[0x4b8696a4], standardtitantx[0x2d39f30a], standardtitantx[0x0da9172d], standardtitantx[0x7c6c7909], standardtitantx[0x79dd0a38], standardtitantx[0x5999c49e], standardtitantx[0x5aaba4a7]] 

任意のヒントをこれは非常に高く評価されます。

答えて

2

エラーは、スキーマを変更しようとすると開いているトランザクションがあることを示しています。 Titanは、スキーマを変更する前にすべてのトランザクションが完了するのを待つ必要があります。詳細は、answer from Matthias Broecheler on the mailing listを参照してください。

一般的に、タイタンはすべての頂点に対してを歩かなければならないので、できる限りインデックスを再作成しないでください。更新するインデックスに追加する必要があるかどうかを確認してください。 The documentationには、このプロセスに関する詳細情報が含まれています。

すべてのインデックスを作成するだけで、データをロードすることができます。すべてのインデックスが準備された後にデータを追加すると、それらのインデックスは単にインデックスに追加されます。そうすれば、インデックスをすぐに使用できるはずです。

Groovyでスキーマ作成のための最小限の例(しかし、それはJavaで基本的に同じでなければなりません):

import com.thinkaurelius.titan.core.TitanFactory; 
import com.thinkaurelius.titan.core.Multiplicity; 
import com.thinkaurelius.titan.core.Cardinality; 

graph = TitanFactory.open('conf/my-titan.properties') 

mgmt = graph.openManagement() 

id = mgmt.makePropertyKey('id').dataType(String.class).cardinality(Cardinality.SINGLE) 

// some other properties that will not be indexed 
mgmt.makePropertyKey('isPublic').dataType(Boolean.class).cardinality(Cardinality.SINGLE) 
mgmt.makePropertyKey('completionPercentage').dataType(Integer.class).cardinality(Cardinality.SINGLE) 

// I prefer to use vertex labels to differentiate between different 'types' of vertices but this isn't necessary 
User = mgmt.makeVertexLabel('User').make() 

mgmt.buildIndex('UserById',Vertex.class).addKey(id).indexOnly(user).buildCompositeIndex() 

mgmt.commit() 

私は簡単にするために、既存のスキーマ要素のためのすべてのチェックを削除していますが、コースをすることができますそれらをもう一度追加してください。 スキーマの作成後、前と同じようにデータを追加できます。

インデックス管理に関する最終ノード:インデックスを作成する同じトランザクションで、インデックスを作成するプロパティキーを常に定義してください。それ以外の場合、Titanは、新しいインデックスに追加する必要のあるデータが既に存在するかどうかを知ることができません。これは、すべてのデータの完全なスキャンを再度必要とします。これは、プロパティのために別の名前を選択する必要があります。たとえば、新しい頂点ラベルに追加すると、プロパティを再度使用する代わりに、のpostIdのような新しい名前を使用して、既存のすべてのデータのスキャンを回避することができます。

+0

こんにちはフロリアン、あなたの答えに感謝します。何らかの理由でメーリングリストのスレッドにアクセスできません。 – jarandaf

+1

申し訳ありませんが、リンクが壊れています。今はうまくいくはずです。ところで、インデックス管理の問題はTitanにとってかなり頻繁に起こります。だから、メーリングリストには、同様の問題の多くの記事があるはずです。 –

+0

データ集計段階(完全性のため)の前に、スキーマ定義と索引作成の最小限の例を提供できますか? :-) – jarandaf

関連する問題