Skip to content

Commit fffdaa7

Browse files
committed
Add backwards compatibility (If we run tarantool 1.6.4 snapshot on tarantool 1.6.6 or more)
1 parent d68e008 commit fffdaa7

File tree

2 files changed

+48
-24
lines changed

2 files changed

+48
-24
lines changed

tarantool/const.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@
4242
SPACE_SPACE = 280
4343
SPACE_INDEX = 288
4444
SPACE_FUNC = 296
45+
SPACE_VSPACE = 281
46+
SPACE_VINDEX = 289
47+
SPACE_VFUNC = 297
4548
SPACE_USER = 304
4649
SPACE_PRIV = 312
4750
SPACE_CLUSTER = 320

tarantool/schema.py

Lines changed: 45 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,26 @@
77

88
import six
99

10-
from tarantool.error import SchemaError
10+
from tarantool.error import SchemaError, DatabaseError
1111
import tarantool.const as const
1212

1313

1414
class SchemaIndex(object):
15-
def __init__(self, array, space):
16-
self.iid = array[1]
17-
self.name = array[2]
15+
def __init__(self, index_row, space):
16+
self.iid = index_row[1]
17+
self.name = index_row[2]
1818
if isinstance(self.name, bytes):
1919
self.name = self.name.decode()
20-
self.index = array[3]
21-
self.unique = array[4]
20+
self.index = index_row[3]
21+
self.unique = index_row[4]
2222
self.parts = []
23-
for i in range(array[5]):
24-
self.parts.append((array[5 + 1 + i * 2], array[5 + 2 + i * 2]))
23+
if isinstance(index_row[5], (list, tuple)):
24+
for k, v in index_row[5]:
25+
self.parts.append(k, v)
26+
else:
27+
for i in range(index_row[5]):
28+
self.parts.append((index_row[5 + 1 + i * 2], index_row[5 + 2 + i * 2]))
29+
sel
2530
self.space = space
2631
self.space.indexes[self.iid] = self
2732
if self.name:
@@ -34,10 +39,10 @@ def flush(self):
3439

3540

3641
class SchemaSpace(object):
37-
def __init__(self, array, schema):
38-
self.sid = array[0]
39-
self.arity = array[1]
40-
self.name = array[2]
42+
def __init__(self, space_row, schema):
43+
self.sid = space_row[0]
44+
self.arity = space_row[1]
45+
self.name = space_row[2]
4146
if isinstance(self.name, bytes):
4247
self.name = self.name.decode()
4348
self.indexes = {}
@@ -66,15 +71,22 @@ def get_space(self, space):
6671
if isinstance(space, six.string_types)
6772
else const.INDEX_SPACE_PRIMARY)
6873

69-
array = self.con.select(const.SPACE_SPACE, space, index=_index)
70-
if len(array) > 1:
71-
raise SchemaError('Some strange output from server: \n' + array)
72-
elif len(array) == 0 or not len(array[0]):
74+
space_row = None
75+
try:
76+
space_row = self.con.select(const.SPACE_VSPACE, space, index=_index)
77+
except DatabaseError as e:
78+
if e.args[0] != 36:
79+
raise
80+
if space_row is None:
81+
space_row = self.con.select(const.SPACE_SPACE, space, index=_index)
82+
if len(space_row) > 1:
83+
raise SchemaError('Some strange output from server: \n' + space_row)
84+
elif len(space_row) == 0 or not len(space_row[0]):
7385
temp_name = ('name' if isinstance(space, six.string_types) else 'id')
7486
raise SchemaError(
7587
"There's no space with {1} '{0}'".format(space, temp_name))
76-
array = array[0]
77-
return SchemaSpace(array, self.schema)
88+
space_row = space_row[0]
89+
return SchemaSpace(space_row, self.schema)
7890

7991
def get_index(self, space, index):
8092
_space = self.get_space(space)
@@ -86,17 +98,26 @@ def get_index(self, space, index):
8698
if isinstance(index, six.string_types)
8799
else const.INDEX_INDEX_PRIMARY)
88100

89-
array = self.con.select(const.SPACE_INDEX, [_space.sid, index],
101+
index_row = None
102+
try:
103+
index_row = self.con.select(const.SPACE_VSPACE, [_space.sid, index],
90104
index=_index)
91-
if len(array) > 1:
92-
raise SchemaError('Some strange output from server: \n' + array)
93-
elif len(array) == 0 or not len(array[0]):
105+
except DatabaseError as e:
106+
if e.args[0] != 36:
107+
raise
108+
if index_row is None:
109+
index_row = self.con.select(const.SPACE_SPACE, [_space.sid, index],
110+
index=_index)
111+
112+
if len(index_row) > 1:
113+
raise SchemaError('Some strange output from server: \n' + index_row)
114+
elif len(index_row) == 0 or not len(index_row[0]):
94115
temp_name = ('name' if isinstance(index, six.string_types) else 'id')
95116
raise SchemaError(
96117
"There's no index with {2} '{0}' in space '{1}'".format(
97118
index, _space.name, temp_name))
98-
array = array[0]
99-
return SchemaIndex(array, _space)
119+
index_row = index_row[0]
120+
return SchemaIndex(index_row, _space)
100121

101122
def flush(self):
102123
self.schema.clear()

0 commit comments

Comments
 (0)