Skip to content

Conversation

@IlyaFaer
Copy link
Collaborator

@IlyaFaer IlyaFaer commented Oct 9, 2020

No description provided.

for transaction in self.transactions:
transaction.rollback()

self.transactions = []
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Commiting and rollbacking all the pending transactions of this connection


self._res = self.transaction.execute_sql(sql)
self._itr = PeekIterator(self._res)
return
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Starting a transaction, if no yet started, or the last one is already commited/rollbacked. Then running SQL request in the current transaction.


def tearDownModule():
if CREATE_INSTANCE:
Config.INSTANCE.delete()
Copy link
Collaborator Author

@IlyaFaer IlyaFaer Oct 9, 2020

Choose a reason for hiding this comment

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

All of the above preparations code is taken from the original Spanner system tests

# TODO: Implement this method
pass
with self._db.snapshot() as snapshot:
snapshot.execute_sql("DELETE FROM contacts WHERE true")
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Clearing the data from the table after every test

@IlyaFaer IlyaFaer requested a review from mf2199 October 9, 2020 14:25
@IlyaFaer
Copy link
Collaborator Author

IlyaFaer commented Oct 9, 2020

@mf2199, I've written the code in more civilized manner and added a system test. Locally everything is working fine so far.
Used several executes within one transaction as Knut was wary about multy-statement transactions.

Copy link
Collaborator

@mf2199 mf2199 left a comment

Choose a reason for hiding this comment

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

Just a couple of suggestions, but looks good overall.

self.transactions = []

self.is_closed = False
self.autocommit = True
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is not something we'd expect the users to change on the fly. Thus, would it make more sense to have it read-only, optionally assignable via the constructor, e.g.:

def __init__(self, instance, database, autocommit=True): ... self._autocommit = autocommit 

and if necessary, add a property getter, WDYT?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We had a word about it with Chris some time ago, and decided to use a property. It can be found in our meetings notes.

We don't have any mentions of autocommit mode in PEP 249, so it seems like we should ask the Java implementation about it:
https://github.com/googleapis/java-spanner-jdbc/blob/cedd167c5973fe50e0205ae641f6580ebd627884/src/main/java/com/google/cloud/spanner/jdbc/JdbcConnection.java#L81-L82

Thus, there will be both setter and getter of this property

@IlyaFaer IlyaFaer closed this Nov 20, 2020
@IlyaFaer IlyaFaer deleted the transactions_retry branch November 20, 2020 08:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

4 participants