Skip to content

Instantly share code, notes, and snippets.

Avatar
🤓
Building awesome stuff with Go

Elliot Chance elliotchance

🤓
Building awesome stuff with Go
View GitHub Profile
View 9.py
class DirtyRead(TransactionTest):
def run(self):
result1 = self.client1.fetch_record(id=1)
self.client2.update_record(id=1, name="Joe 2")
result2 = self.client1.fetch_record(id=1)
return result1 != result2
class NonRepeatableRead(TransactionTest):
def run(self):
result1 = self.client1.fetch_record(id=1)
View 8.py
class TransactionTest:
def __init__(self, transaction_type):
self.table = Table()
client = self.table.new_transaction(ReadCommittedTransaction)
client.add_record(id=1, name="Joe")
client.add_record(id=3, name="Jill")
client.commit()
self.client1 = self.table.new_transaction(transaction_type)
self.client2 = self.table.new_transaction(transaction_type)
View 7.py
class SerializableTransaction(RepeatableReadTransaction):
def __init__(self, table, xid):
Transaction.__init__(self, table, xid)
self.existing_xids = self.table.active_xids.copy()
def record_is_visible(self, record):
is_visible = ReadCommittedTransaction.record_is_visible(self, record) \
and record['created_xid'] <= self.xid \
and record['created_xid'] in self.existing_xids
View 6.py
class LockManager:
def __init__(self):
self.locks = []
def add(self, transaction, record_id):
if not self.exists(transaction, record_id):
self.locks.append([transaction, record_id])
def exists(self, transaction, record_id):
return any(lock[0] is transaction and lock[1] == record_id \
View 5.py
class RepeatableReadTransaction(ReadCommittedTransaction):
def record_is_locked(self, record):
return ReadCommittedTransaction.record_is_locked(self, record) or \
self.table.locks.exists(self, record['id'])
def record_is_visible(self, record):
is_visible = ReadCommittedTransaction.record_is_visible(self, record)
if is_visible:
self.table.locks.add(self, record['id'])
View 4.py
class ReadCommittedTransaction(Transaction):
def record_is_locked(self, record):
return record['expired_xid'] != 0 and \
row['expired_xid'] in self.table.active_xids
def record_is_visible(self, record):
# The record was created in active transaction that is not our
# own.
if record['created_xid'] in self.table.active_xids and \
record['created_xid'] != self.xid:
View 3.py
class ReadUncommittedTransaction(Transaction):
def record_is_locked(self, record):
return record['expired_xid'] != 0
def record_is_visible(self, record):
return record['expired_xid'] == 0
View 1.py
class Transaction:
def __init__(self, table, xid):
self.table = table
self.xid = xid
self.rollback_actions = []
def add_record(self, id, name):
record = {
'id': id,
'name': name,
View 1.go
import "golang.org/x/crypto/bcrypt"
// CheckPassword is used for Basic authentication to check the secret. The logic
// has been copied from the existing implementation in:
//
// protected/models/traits/HasPassword.php
//
// The PHP source code will be copied verbatim here, just in case something
// changes it can be compared:
//
You can’t perform that action at this time.