Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unique index failed when vertex creation running in parallel #1375

Open
xdev-developer opened this issue Feb 18, 2017 · 0 comments
Open

Unique index failed when vertex creation running in parallel #1375

xdev-developer opened this issue Feb 18, 2017 · 0 comments

Comments

@xdev-developer
Copy link

xdev-developer commented Feb 18, 2017

Hi all.
Unique index not working when run vertex creation in parallel.
Titan version 1.0.0

How to reproduce.

import java.io.File

import com.thinkaurelius.titan.core.{TitanFactory, TitanGraph}
import org.apache.commons.configuration.BaseConfiguration
import org.apache.commons.io.{FileUtils, IOUtils}
import org.apache.tinkerpop.gremlin.structure.{Graph, Vertex}

import scala.concurrent.duration._
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.{Await, Future}
import scala.util.Random

object Launcher {

  val DB_DIR = "/tmp/titan-index-test"

  def openGraph(): Graph = {
    val conf = new BaseConfiguration()
    conf.setProperty("schema.default", "none")
    conf.setProperty("storage.backend", "berkeleyje")
    conf.setProperty("storage.directory", "/tmp/titan-index-test")
    createSchema(TitanFactory.open(conf))
  }

  def createSchema(graph: TitanGraph): TitanGraph = {
    val mgmt = graph.openManagement()
    val label = mgmt.makeVertexLabel("user").make()
    val key = mgmt.makePropertyKey("username").dataType(classOf[String]).make()
    val pass = mgmt.makePropertyKey("pass").dataType(classOf[String]).make()

    mgmt.buildIndex("usernameUnique", classOf[Vertex]).addKey(key).indexOnly(label).unique().buildCompositeIndex()

    mgmt.commit()
    graph
  }

  def main(args: Array[String]): Unit = {
    System.out.println("Start application")
    FileUtils.deleteQuietly(new File(DB_DIR))

    val graph = openGraph()

    (1 to 10).foreach { i =>
      println("test: " + i)

      val fSeq = Future.sequence(test(graph))

      println("Awaiting")
      Await.result(fSeq, 1.minute)

      val count = graph.traversal().V().has("username", "Den").count().next()
      println("Count of vertices: " + count)
      assert(count == 1, "Users > 1")
    }

    println("Closing application")
    graph.close()
    System.exit(0)
  }

  def test(graph: Graph): List[Future[Boolean]] = {
    (1 to 10).toList.map { _ =>
      Future {
        try {
          println("Add vertex!!!")
          val v = graph.addVertex("user")
          v.property("pass", "test")
          v.property("username", "Den")
          graph.tx().commit()
          true
        } catch {
          case ex: Exception =>
            println(ex.getMessage)
            false
        }
      }
    }
  }
}

Result:

Adding this property for key [username] and value [Den] violates a uniqueness constraint [usernameUnique]
Adding this property for key [username] and value [Den] violates a uniqueness constraint [usernameUnique]
Adding this property for key [username] and value [Den] violates a uniqueness constraint [usernameUnique]
Adding this property for key [username] and value [Den] violates a uniqueness constraint [usernameUnique]
Count of vertices: 2
Exception in thread "main" java.lang.AssertionError: assertion failed: Users > 1
	at scala.Predef$.assert(Predef.scala:170)
	at com.xdev.titan.Launcher$$anonfun$main$1.apply$mcVI$sp(Launcher.scala:55)
	at scala.collection.immutable.Range.foreach$mVc$sp(Range.scala:160)
	at com.xdev.titan.Launcher$.main(Launcher.scala:45)
	at com.xdev.titan.Launcher.main(Launcher.scala)

This additional vertex cannot be removed, operation failed with status NOT_FOUND.

@xdev-developer xdev-developer changed the title Unique index not working. Unique index failed when vertex creation running in parallel Feb 18, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant