Commit f954f851 authored by Vincent Pelletier's avatar Vincent Pelletier

Protect more iterating calls against ValueError.

Also, factorise existing checks.

git-svn-id: https://svn.erp5.org/repos/neo/trunk@2452 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent 170805d7
...@@ -82,6 +82,13 @@ def descKeys(tree): ...@@ -82,6 +82,13 @@ def descKeys(tree):
except ValueError: except ValueError:
break break
def safeIter(func, *args, **kw):
try:
some_list = func(*args, **kw)
except ValueError:
some_list = []
return some_list
class BTreeDatabaseManager(DatabaseManager): class BTreeDatabaseManager(DatabaseManager):
_obj = None _obj = None
...@@ -431,7 +438,7 @@ class BTreeDatabaseManager(DatabaseManager): ...@@ -431,7 +438,7 @@ class BTreeDatabaseManager(DatabaseManager):
partition_list = frozenset(partition_list) partition_list = frozenset(partition_list)
result = [] result = []
append = result.append append = result.append
for oid in self._obj.keys(min=min_oid): for oid in safeIter(self._obj.keys, min=min_oid):
if oid % num_partitions in partition_list: if oid % num_partitions in partition_list:
if length == 0: if length == 0:
break break
...@@ -494,11 +501,7 @@ class BTreeDatabaseManager(DatabaseManager): ...@@ -494,11 +501,7 @@ class BTreeDatabaseManager(DatabaseManager):
min_serial = u64(min_serial) min_serial = u64(min_serial)
max_serial = u64(max_serial) max_serial = u64(max_serial)
result = {} result = {}
try: for oid, tserial in safeIter(self._obj.items, min=min_oid):
oid_set = self._obj.items(min=min_oid)
except ValueError:
oid_set = []
for oid, tserial in oid_set:
if oid % num_partitions == partition: if oid % num_partitions == partition:
result[p64(oid)] = tid_list = [] result[p64(oid)] = tid_list = []
append = tid_list.append append = tid_list.append
...@@ -543,11 +546,7 @@ class BTreeDatabaseManager(DatabaseManager): ...@@ -543,11 +546,7 @@ class BTreeDatabaseManager(DatabaseManager):
u64 = util.u64 u64 = util.u64
result = [] result = []
append = result.append append = result.append
try: for tid in safeIter(self._trans.keys, min=u64(min_tid), max=u64(max_tid)):
tid_seq = self._trans.keys(min=u64(min_tid), max=u64(max_tid))
except ValueError:
tid_seq = []
for tid in tid_seq:
if tid % num_partitions == partition: if tid % num_partitions == partition:
if length == 0: if length == 0:
break break
...@@ -596,7 +595,7 @@ class BTreeDatabaseManager(DatabaseManager): ...@@ -596,7 +595,7 @@ class BTreeDatabaseManager(DatabaseManager):
while True: while True:
obj_to_drop = [] obj_to_drop = []
append_obj = obj_to_drop.append append_obj = obj_to_drop.append
for oid, tserial in obj.items(min=last_obj): for oid, tserial in safeIter(obj.items, min=last_obj):
try: try:
max_serial = tserial.maxKey(tid) max_serial = tserial.maxKey(tid)
except ValueError: except ValueError:
...@@ -642,7 +641,7 @@ class BTreeDatabaseManager(DatabaseManager): ...@@ -642,7 +641,7 @@ class BTreeDatabaseManager(DatabaseManager):
count = 0 count = 0
tid_checksum = 0 tid_checksum = 0
max_tid = 0 max_tid = 0
for max_tid in self._trans.keys(min=util.u64(min_tid)): for max_tid in safeIter(self._trans.keys, min=util.u64(min_tid)):
if max_tid % num_partitions == partition: if max_tid % num_partitions == partition:
if count >= length: if count >= length:
break break
...@@ -659,7 +658,7 @@ class BTreeDatabaseManager(DatabaseManager): ...@@ -659,7 +658,7 @@ class BTreeDatabaseManager(DatabaseManager):
count = 0 count = 0
oid_checksum = serial_checksum = 0 oid_checksum = serial_checksum = 0
max_oid = max_serial = 0 max_oid = max_serial = 0
for max_oid, tserial in self._obj.items(min=min_oid): for max_oid, tserial in safeIter(self._obj.items, min=min_oid):
if max_oid % num_partitions == partition: if max_oid % num_partitions == partition:
if max_oid == min_oid: if max_oid == min_oid:
try: try:
......
Markdown is supported
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