Skip to content
New issue

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

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

Already on GitHub? # to your account

Multiple bookmarks #376

Merged
merged 2 commits into from
May 24, 2017
Merged

Multiple bookmarks #376

merged 2 commits into from
May 24, 2017

Conversation

lutovich
Copy link
Contributor

@lutovich lutovich commented May 22, 2017

Previously it was possible to only supply a single bookmark when creating a new session. However there is a use-case to be able to supply multiple bookmarks when multiple worker threads execute write queries and then reader should be able to observe all those writes. To achieve this driver now exposed session creation methods that take an iterable of bookmarks.

It was chosen to add additional Driver#session() overloads with Iterable<String> instead of extending single-bookmark methods with varargs because:

  • this maintains backwards compatibility for pre-existing methods
  • addition of varargs would make API look strange because call or Driver#session() and call of Driver#session(String... bookmarks) without params is essentially the same thing
  • invocation of vararg methods with single null argument can be confusing
  • varargs are more suitable for manual params listing

Driver will now send:

{
    bookmark: "max",
    bookmarks: ["one", "two", "max"]
}

instead of simple:

{
    bookmark: "max"
}

this is done to maintain backwards compatibility with databases that only support single bookmark. It forces driver to parse and compare bookmarks which violates the fact that bookmarks are opaque. This is done only to maintain backwards compatibility and should not be copied. Code doing this will eventually be removed.

Related Bolt server PR: neo4j/neo4j#9404

while ( iterator.hasNext() )
{
String bookmark = iterator.next();
long value = bookmarkValue( bookmark );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

value might be null for the following case:
bookmarks = new String[]{aBookmark, null, null};

}

@Override
public Session session( Collection<String> bookmarks )
Copy link
Contributor

@zhenlineo zhenlineo May 23, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Five methods can be merged in to two

public Session session( String... bookmark )
public Session session( AccessMode mode, String... bookmark )

return maxValue;
}

public Map<String,Value> asParameters()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe asBeginTransactionParameters()?

Previously it was possible to only supply a single bookmark when creating
a new session. However there is a use-case to be able to supply multiple
bookmarks when multiple worker threads execute write queries and then
reader should be able to observe all those writes. To achieve this driver
now exposed session creation methods that take an iterable of bookmarks.

It was chosen to add additional `Driver#session()` overloads with
`Iterable<String>` instead of extending single-bookmark methods with
varargs because:
 * this maintains backwards compatibility for pre-existing methods
 * addition of varargs would make API look strange because call or
   `Driver#session()` and call of `Driver#session(String... bookmarks)`
   without params is essentially the same thing
 * invocation of vararg methods with single `null` argument can be confusing
 * varargs are more suitable for manual params listing

Driver will now send:
```
{
    bookmark: "max",
    bookmarks: ["one", "two", "max"]
}
```
instead of simple:
```
{
    bookmark: "max"
}
```
this is done to maintain backwards compatibility with databases that
only support single bookmark. It forces driver to parse and compare
bookmarks which violates the fact that bookmarks are opaque. This is
done only to maintain backwards compatibility and should not be copied.
Code doing this will eventually be removed.
@lutovich lutovich force-pushed the 1.4-multiple-bookmarks branch from d27a29a to f186165 Compare May 24, 2017 08:48
return maxValue == null;
}

public String asString()
Copy link
Contributor

@zhenlineo zhenlineo May 24, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method name is confusing in a way that I would question why only return one bookmark rather than all of them back (like toString method).
Maybe change to names like asSingleString(), or maxBookmarkAsString, or singleBookmarkAsString?

}

@Test
public void bookmarkFromIterable()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about a test for

Bookmark bookmark = Bookmark.from( asList(
               null, "neo4j:bookmark:v1:tx10", "neo4j:bookmark:v1:tx12" ) );

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

 * improve method naming in `Bookmark`
 * handle `null` bookmark in given `Iterable`
@zhenlineo
Copy link
Contributor

LGTM

@lutovich lutovich merged commit 90b01d2 into neo4j:1.4 May 24, 2017
@lutovich lutovich deleted the 1.4-multiple-bookmarks branch May 24, 2017 10:00
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants