Skip to content
This repository was archived by the owner on Mar 11, 2022. It is now read-only.

291 refactor datastore callables part 3#356

Merged
tomblench merged 1 commit intomasterfrom
291-refactor-datastore-callables-part-3
Sep 20, 2016
Merged

291 refactor datastore callables part 3#356
tomblench merged 1 commit intomasterfrom
291-refactor-datastore-callables-part-3

Conversation

@tomblench
Copy link
Contributor

@tomblench tomblench commented Sep 14, 2016

Everything except AttachmentManager into callables

TODO

  • Check exception correctness DatastoreImpl signatures haven't changed so they still throw the same exceptions. See Refactor - fix exception handling in Callables #354 and Unchecked exception audit #280 - these are the correct follow on PRs to use to address the other exception issues
  • Fix up catch(InterruptedException e)/ catch (ExecutionException e) pattern in DatastoreImpl
  • javadoc comments
  • Copyright headers
  • Run some proper replication tests - pull and pull replication looks good with the Airfi dataset

private final List<DocumentRevision> results;

protected Changes(long lastSequence, List<DocumentRevision> results) {
public Changes(long lastSequence, List<DocumentRevision> results) {
Copy link
Member

Choose a reason for hiding this comment

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

Perhaps add a comment indicating that API users are not expected to construct this and should call com.cloudant.sync.datastore.Datastore#changes since it is now publicly visible.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See 0aaed80

InsertRevisionCallable insertRevisionCallable = this.insertNewWinnerRevisionAdaptor(body, preRevision);
String newRevisionId = insertRevisionCallable.revId;
insertRevisionCallable.call(db);
return new GetDocumentCallable(docId, newRevisionId, this.attachmentsDir, this.attachmentStreamFactory).call(db);
Copy link
Member

Choose a reason for hiding this comment

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

Should this be a TODO as well to build the new DocumentRevision instead of retrieving the whole document again?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See 23ce739 - we can sweep these all up into a ticket/gist to use in a later PR

}
// before starting the tx, get the 'new winner' and see if we need to prepare its
// attachments
DocumentRevisionTree docTree = queue.submit(new GetAllRevisionsOfDocumentCallable(docId, attachmentsDir, attachmentStreamFactory)).get();
Copy link
Member

Choose a reason for hiding this comment

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

Before all parts of this resolution were in a single transaction. Do you think it is safe to do it in parts? I guess the revisions of the document could change between this get and the later resolve and update of attachments.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for spotting, restored in 78a8c67

Copy link
Member

Choose a reason for hiding this comment

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

The first getAllRevisionsOfDocumentCallable is still not part of the tx, was that oversight or intentional?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh I was following the comment but yes in the original version it was inside the transaction. It possibly doesn't make much/any difference because getAllRevisionsOfDocumentCallable doesn't modify the database, but I could put it back in the transaction to be consistent with the original code.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah considering the scenarios:

  1. rev1, rev2 <- getAllRevisionsOfDocumentCallable
  2. New rev3 inserted
  3. Transaction
    1. Resolve conflicts between rev1 and rev2
  4. Conflict exists with rev3

vs

  1. Transaction
    1. rev1, rev2 <- getAllRevisionsOfDocumentCallable
    2. Resolve conflicts between rev1 and rev2
  2. New rev3 inserted
  3. Conflict exists with rev3

The outcome isn't different even though it seems like the second case provides some protection against a new conflict being created during the resolution so you're right there probably isn't anything further to be gained.

existingAttachments, attachmentsDir, attachmentStreamFactory)).get();
}
} catch (AttachmentException e) {
// TODO
Copy link
Member

Choose a reason for hiding this comment

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

Think we should at least add a log message here before merging even if a more robust solution is intended in a later pass.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Due to changes in 78a8c67 this should no longer be present

}

private String insertNewWinnerRevision(SQLDatabase db, DocumentBody newWinner,
// TODO should this be a callable itself?
Copy link
Member

Choose a reason for hiding this comment

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

I don't think so because it doesn't run against the DB, which I think was the pattern for the callables.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed. Done in 78a8c67

}

/**
* @return Whether the body has been modified
Copy link
Member

Choose a reason for hiding this comment

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

modified since when?

DocumentRevision is api_public so we should try to be clear about what the method does or is for or possibly just say it is for internal use.

public List<DocumentRevision> call(SQLDatabase db) throws Exception {
String sql = String.format("SELECT " + DatastoreImpl.FULL_DOCUMENT_COLS + " FROM revs, docs" +
" WHERE docid IN ( %1$s ) AND current = 1 AND docs.doc_id = revs" +
".doc_id " +
Copy link
Member

Choose a reason for hiding this comment

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

formatting is a bit weird here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 9d866f0

@ricellis ricellis self-assigned this Sep 15, 2016
@tomblench tomblench force-pushed the 291-refactor-datastore-callables-part-3 branch 2 times, most recently from 5d7aa9b to 2c4c991 Compare September 20, 2016 14:44
Almost everything else is now in callables except `AttachmentManager` code.
@tomblench tomblench force-pushed the 291-refactor-datastore-callables-part-3 branch from ea7a55f to d36f18c Compare September 20, 2016 15:35
@tomblench tomblench merged commit 047f66d into master Sep 20, 2016
@rhyshort rhyshort deleted the 291-refactor-datastore-callables-part-3 branch January 13, 2017 10:40
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants