Search code examples
gogremlinamazon-neptunegremlin-server

Gremlingo stuck while evaluting g.V().hasNext()


I have a piece of code where i evaluate to drop vertices but only if a pre-fetch of g.V().<filters>.hasNext() returns true.

Problem is on my subsequent call to fetch the nodes themselves it is getting stuck for some reason.

hasNext, err := g.V().<filter>.hasNext()

if err != nil {
  return err 
}

if hasNext {

   // Program is stuck here
   ids, err := g.V().<filter>.Id().ToList()
   ....
}



Solution

  • I found out what was causing this to be stuck indefinitely.

    It looks like the go version of gremlingo has a weird implementation of HasNext(). Instead of adding it as a strategy it fetches the complete results, and then returns if the results are non-empty, which in my opinion is not helpful at all when checking for any results.

    Error: https://github.com/apache/tinkerpop/blob/master/gremlin-go/driver/traversal.go#L99

    This seems to wait until receiving a signal on the waitChannel externally. https://github.com/apache/tinkerpop/blob/master/gremlin-go/driver/resultSet.go#L107

    There doesnt seem to be a way to signal this to stop.

    Python:

    The python version of the gremlin library and im sure other versions as well, use this function as a strategy.

    https://github.com/apache/tinkerpop/pull/927/files#diff-bf65a33ee80dbc36f03915459a68114aa5d2fb54217588f18832e23be29822dcR77

    Workaround:

    I needed a lightweight query to tell me if there are more results in my query criteria and i used this instead of the HasNext()

    res, err := g.V().<filters>.Limit(1).ToList()
    
    if len(res) == 0 {
       // no more results
    } else {
      // results available
    }