Every example I've been able to find in the Titan documentation creates indices using the Rexster console. You log in to a single Titan node, create your indices and commit. After a while the whole cluster is aware of the index and it can be used.
I am wondering if there are other ways to do this. There are some benefits when creating indices from code e.g. in a Rexster extension: I use ENUMs for property keys and edge labels that offer toString
methods I can use on index creation. This way there is no worry about changed values.
Another aspect to mention is that I benchmark Titan and thus reinitialize the cluster quite often. It is more comfortable to let the code do all the work for me than logging in to a node and do it manually.
However, creating indices from code seems to be a mess and caused multiple exceptions when using an eventually-consistent storage backend. I think due to my simultaneous node startup multiple nodes tried to create the indices. See Titan node does not come up for details.
Is there a proper way of handling these issues? Are there further methods I am not aware of?
In practice, I don't think many people create their schema by manually typing things into the console. I typically create a
Schema
class that has some methods to do that work. In that way, I can use enums, static string variables, etc. in the way you are describing. ThatSchema
class is really useful, because it represents a versioned instance of what my Titan schema looks like at any given time and I can re-use it in lots of places (to initialize a production instance manually, construct schema between unit tests, work it into a groovy script to use for automation on your build server, etc.)For Titan, the
Schema
class is quite central to the concept of developing and maintaining a custom Gremlin DSL. You may find this blog post on the topic interesting if you have not already read it.