Skip to content
Snippets Groups Projects
Commit 760a7550 authored by Ahmad Naufal Hakim's avatar Ahmad Naufal Hakim
Browse files

Add ctor and edit few functions

parent db84eefb
No related merge requests found
import storage
import storage as strg
import time
class MVCC :
def __init__(self) :
return
def getTimestampNow(self) :
return time.time()
def setTimestampNow(self, key, timestamp, storage = Storage) :
def setTimestampNow(self, key, timestamp, storage : strg) :
tempTimestamp = timestamp
storage.setdata[key]["timestamp"] = tempTimestamp
def read(self, key, storage = Storage) :
def read(self, key, storage : strg) :
return storage.setdata[key]["value"]
def write(self, key, value, storage = Storage) :
def write(self, key, value, storage : strg) :
tempTimestamp = self.getTimestampNow()
if (storage.setdata[key]["timestamp"] > tempTimestamp) :
# rollback transaction and reject operation
# rollback transaction
# reject operation
return False
else :
storage.setdata[key]["value"] = value
self.setTimestampNow(key, tempTimestamp, storage)
\ No newline at end of file
self.setTimestampNow(key, tempTimestamp, storage)
return True
\ No newline at end of file
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment