Skip to content

Commit

Permalink
remove some flushes
Browse files Browse the repository at this point in the history
  • Loading branch information
Knio committed May 1, 2015
1 parent 2e6ecbd commit 66fcc66
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 25 deletions.
6 changes: 3 additions & 3 deletions everdb/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ def resize(self, length):
# no zero fill when growing, since we assume the block was
# zeroed either above or on blob creation
self.length = length
self.flush_root()
self.sync_header()
return

# requested size requires a regular blob
Expand All @@ -204,7 +204,7 @@ def resize(self, length):
s = slice(length % self.items_per_block, BLOCK_SIZE)
b[s] = ZERO_BLOCK[s]
self.length = length
self.flush_root()
self.sync_header()
return

self.last_block = None
Expand All @@ -216,7 +216,7 @@ def resize(self, length):
self.allocate(num_blocks)

self.length = length
self.flush_root()
self.sync_header()

def __repr__(self):
return '''<Array(root=%d, type=%d, format=%s, num_blocks=%d, length=%d)>''' % \
Expand Down
8 changes: 4 additions & 4 deletions everdb/blob.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def write(self, offset, data):
i += l
if self.type == SMALL_PAGE:
# TODO don't do this
self.sync_header(self.host[self.root])
self.sync_header()

def resize(self, length):
'''
Expand Down Expand Up @@ -102,7 +102,7 @@ def resize(self, length):
# no zero fill when growing, since we assume the block was
# zeroed either above or on blob creation
self.length = length
self.flush_root()
self.sync_header()
return

# requested size requires a regular blob
Expand All @@ -117,7 +117,7 @@ def resize(self, length):
s = slice(OFFSET(length), OFFSET(self.length - 1) + 1)
b[s] = ZERO_BLOCK[s]
self.length = length
self.flush_root()
self.sync_header()
return

if self.type == SMALL_PAGE:
Expand All @@ -127,7 +127,7 @@ def resize(self, length):
self.allocate(num_blocks)

self.length = length
self.flush_root()
self.sync_header()

def __repr__(self):
return '''<Blob(root=%d, type=%d, num_blocks=%d, length=%d)>''' % \
Expand Down
12 changes: 6 additions & 6 deletions everdb/hash.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def init_root(self):
super(Bucket, self).init_root()
self.resize(SUB_BUCKET << 2)
self.get_header()[:] == [0] * SUB_BUCKET
self.flush_root()
self.sync_header()

def get_header(self):
if self.num_blocks == 0:
Expand Down Expand Up @@ -96,7 +96,7 @@ def set_sub(self, i, bucket):
h[i << 1] = 0
else:
self.write(o, data)
self.sync_header(self.host[self.root])
self.sync_header()
return
# find and allocate new space for the sub bucket
h[i << 1], h[(i << 1) + 1] = 0, 0
Expand All @@ -122,7 +122,7 @@ def set_sub(self, i, bucket):

self.write(o, data)
# TODO don't do this
self.sync_header(self.host[self.root])
self.sync_header()

def items(self):
b = {}
Expand Down Expand Up @@ -187,7 +187,7 @@ def set(self, key, value):
if key not in bucket:
self.size += 1
# TODO don't do this
self.sync_header(self.host[self.root])
self.sync_header()

bucket[key] = self.pack_value(value)
blob.set_sub(s, bucket)
Expand All @@ -202,7 +202,7 @@ def pop(self, key):
blob.set_sub(s, bucket)

self.size -= 1
self.flush_root()
self.sync_header()

# TODO shrink
return self.unpack_value(value)
Expand Down Expand Up @@ -279,7 +279,7 @@ def grow(self):
else:
self.split += 1

self.sync_header(self.host[self.root])
self.sync_header()

for k, v in bucket.items():
assert [0, self[k]] == v
Expand Down
25 changes: 13 additions & 12 deletions everdb/page.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,29 +58,30 @@ def root_block(self):
def index(self):
return self.host[self.root][0:-self._header_size & ~4 + 1].cast('I')

def flush_root(self):
self.sync_header(self.root_block)
# print('flush, checksum = %d' % self.checksum)
def sync_header(self):
Header.sync_header(self, self.host[self.root])

def flush_header(self):
self.sync_header()
self.host.flush(self.root)

def init_root(self):
self.host[self.root] = ZERO_BLOCK # do we need to do this?
self.num_blocks = 0
self.type = SMALL_PAGE
self.flush_root()
self.sync_header()

def flush(self, b=-1):
if b == -1:
# TODO keep track of just these blocks
self.flush_root()
self.sync_header()
self.host.flush()
else:
self.host.flush(self.get_host_index(b))

def close(self):
if not self.host.readonly:
self.flush()
self.flush_root()
self.flush_header()

def get_host_index(self, i):
# translate a local block pointer to a host block pointer
Expand Down Expand Up @@ -112,7 +113,7 @@ def make_small(self):
self.allocate(0)
self.type = SMALL_PAGE
self.host[self.root][0:-self._header_size] = data
self.flush_root()
self.sync_header()

def make_regular(self):
if self.type == REGULAR_PAGE: return
Expand All @@ -124,7 +125,7 @@ def make_regular(self):
self.index[0] = b
self.type = REGULAR_PAGE
self.num_blocks = 1
self.flush_root()
self.sync_header()

def get_block(self, i):
return self.host.get_block(self.get_host_index(i))
Expand Down Expand Up @@ -227,9 +228,9 @@ def allocate(self, num_blocks):
self.num_blocks = cur_blocks

# cleanup
for b in dirty:
self.host.flush(b)
self.flush_root()
# for b in dirty:
# self.host.flush(b)
self.sync_header()

def __repr__(self):
return '''<Page(root=%d, type=%d, num_blocks=%d)>''' % \
Expand Down

0 comments on commit 66fcc66

Please sign in to comment.