Skip to content

Commit 34adc4c

Browse files
committed
issue=#382 add rollback cases
1 parent 76200b3 commit 34adc4c

File tree

2 files changed

+165
-10
lines changed

2 files changed

+165
-10
lines changed

src/master/tablet_manager.cc

+14-10
Original file line numberDiff line numberDiff line change
@@ -362,22 +362,26 @@ void Tablet::ListRollback(std::vector<Rollback>* rollbacks) {
362362
MutexLock lock(&m_mutex);
363363
for (int i = 0; i < m_meta.rollbacks_size(); i++) {
364364
rollbacks->push_back(m_meta.rollbacks(i));
365+
VLOG(11) << "rollback " << m_meta.path() << ": " << m_meta.rollbacks(i).ShortDebugString();
365366
}
366367
}
367368

368369
int32_t Tablet::UpdateRollback(std::string name, uint64_t snapshot_id, uint64_t rollback_point) {
369-
MutexLock lock(&m_mutex);
370-
bool has_rollback_name = false;
371-
for (int32_t i = 0; i < m_meta.rollbacks_size(); ++i) {
372-
Rollback cur_rollback = m_meta.rollbacks(i);
373-
if (cur_rollback.name() == name) {
370+
MutexLock lock(&m_mutex);
371+
bool has_rollback_name = false;
372+
for (int32_t i = 0; i < m_meta.rollbacks_size(); ++i) {
373+
Rollback* cur_rollback = m_meta.mutable_rollbacks(i);
374+
if (cur_rollback->name() == name) {
374375
has_rollback_name = true;
375-
assert(cur_rollback.snapshot_id() == snapshot_id);
376-
cur_rollback.set_rollback_point(rollback_point);
376+
assert(cur_rollback->snapshot_id() == snapshot_id);
377+
cur_rollback->set_rollback_point(rollback_point);
377378
}
378-
}
379-
assert(has_rollback_name);
380-
return m_meta.rollbacks_size() - 1;
379+
}
380+
for (int i = 0; i < m_meta.rollbacks_size(); i++) {
381+
VLOG(11) << "rollback " << m_meta.path() << ": " << m_meta.rollbacks(i).ShortDebugString();
382+
}
383+
assert(has_rollback_name);
384+
return m_meta.rollbacks_size() - 1;
381385
}
382386

383387
bool Tablet::IsBound() {

test/testcase/test_rollback.py

+151
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
"""
2+
Copyright (c) 2015, Baidu.com, Inc. All Rights Reserved
3+
Use of this source code is governed by a BSD-style license that can be
4+
found in the LICENSE file.
5+
"""
6+
7+
import nose
8+
import time
9+
10+
import common
11+
from conf import const
12+
13+
14+
@nose.tools.with_setup(common.create_kv_table, common.cleanup)
15+
def test_rollback_kv():
16+
"""
17+
test kv rollback
18+
1. write data set 1
19+
2. create snapshot
20+
3. write data set 2
21+
4. scan & compare with set 2
22+
5. rollback to snapshot
23+
6. scan & compare snapshot 1
24+
7. compact then compare
25+
:return:
26+
"""
27+
table_name = 'test'
28+
dump_file1 = 'dump1.out'
29+
dump_file2 = 'dump2.out'
30+
scan_file = 'scan.out'
31+
common.run_tera_mark([(dump_file1, False)], op='w', table_name=table_name, random='random',
32+
key_seed=1, value_seed=10, value_size=100, num=10000, key_size=20)
33+
snapshot = common.snapshot_op(table_name)
34+
common.run_tera_mark([(dump_file2, False)], op='w', table_name=table_name, random='random',
35+
key_seed=1, value_seed=11, value_size=100, num=10000, key_size=20)
36+
common.scan_table(table_name=table_name, file_path=scan_file, allversion=False, snapshot=0)
37+
nose.tools.assert_true(common.compare_files(dump_file2, scan_file, need_sort=True))
38+
39+
common.rollback_op(table_name, snapshot, 'roll')
40+
common.scan_table(table_name=table_name, file_path=scan_file, allversion=False, snapshot=0)
41+
nose.tools.assert_true(common.compare_files(dump_file1, scan_file, need_sort=True))
42+
43+
common.compact_tablets(common.get_tablet_list(table_name))
44+
nose.tools.assert_true(common.compare_files(dump_file1, scan_file, need_sort=False))
45+
46+
47+
@nose.tools.with_setup(common.create_singleversion_table, common.cleanup)
48+
def test_rollback_table():
49+
"""
50+
test table rollback
51+
1. write data set 1
52+
2. create snapshot
53+
3. write data set 2
54+
4. scan & compare with set 2
55+
5. rollback to snapshot
56+
6. scan & compare snapshot 1
57+
7. compact then compare
58+
:return:
59+
"""
60+
table_name = 'test'
61+
dump_file1 = 'dump1.out'
62+
dump_file2 = 'dump2.out'
63+
scan_file = 'scan.out'
64+
common.run_tera_mark([(dump_file1, False)], op='w', table_name=table_name, cf='cf0:q,cf1:q', random='random',
65+
key_seed=1, value_seed=10, value_size=100, num=10000, key_size=20)
66+
snapshot = common.snapshot_op(table_name)
67+
common.run_tera_mark([(dump_file2, False)], op='w', table_name=table_name, cf='cf0:q,cf1:q', random='random',
68+
key_seed=1, value_seed=11, value_size=100, num=10000, key_size=20)
69+
common.scan_table(table_name=table_name, file_path=scan_file, allversion=False, snapshot=0)
70+
nose.tools.assert_true(common.compare_files(dump_file2, scan_file, need_sort=True))
71+
72+
common.rollback_op(table_name, snapshot, 'roll')
73+
common.scan_table(table_name=table_name, file_path=scan_file, allversion=False, snapshot=0)
74+
nose.tools.assert_true(common.compare_files(dump_file1, scan_file, need_sort=True))
75+
76+
common.compact_tablets(common.get_tablet_list(table_name))
77+
nose.tools.assert_true(common.compare_files(dump_file1, scan_file, need_sort=True))
78+
79+
80+
@nose.tools.with_setup(common.create_kv_table)
81+
def test_rollback_kv_relaunch():
82+
"""
83+
test kv rollback w/relaunch
84+
1. test_rollback_kv()
85+
2. relaunch
86+
3. compare
87+
:return:
88+
"""
89+
table_name = 'test'
90+
dump_file1 = 'dump1.out'
91+
scan_file = 'scan.out'
92+
test_rollback_kv()
93+
94+
common.cluster_op('kill')
95+
common.cluster_op('launch')
96+
time.sleep(2)
97+
98+
common.scan_table(table_name=table_name, file_path=scan_file, allversion=False, snapshot=0)
99+
nose.tools.assert_true(common.compare_files(dump_file1, scan_file, need_sort=True))
100+
101+
common.compact_tablets(common.get_tablet_list(table_name))
102+
nose.tools.assert_true(common.compare_files(dump_file1, scan_file, need_sort=False))
103+
104+
105+
@nose.tools.with_setup(common.create_singleversion_table, common.cleanup)
106+
def test_rollback_table_relaunch():
107+
"""
108+
test table rollback w/relaunch
109+
1. test_rollback_table()
110+
2. relaunch
111+
3. compare
112+
:return:
113+
"""
114+
table_name = 'test'
115+
dump_file1 = 'dump1.out'
116+
scan_file = 'scan.out'
117+
test_rollback_table()
118+
119+
common.cluster_op('kill')
120+
common.cluster_op('launch')
121+
time.sleep(2)
122+
123+
common.scan_table(table_name=table_name, file_path=scan_file, allversion=False, snapshot=0)
124+
nose.tools.assert_true(common.compare_files(dump_file1, scan_file, need_sort=True))
125+
126+
common.compact_tablets(common.get_tablet_list(table_name))
127+
nose.tools.assert_true(common.compare_files(dump_file1, scan_file, need_sort=False))
128+
129+
130+
@nose.tools.with_setup(None, common.cleanup)
131+
def test_rollback_kv_multitablets():
132+
"""
133+
test kv rollback w/multi tablets
134+
1. test_rollback_kv_relaunch()
135+
:return:
136+
"""
137+
138+
common.createbyfile(schema=const.data_path + 'kv.schema', deli=const.data_path + 'deli.10')
139+
test_rollback_kv_relaunch()
140+
141+
142+
@nose.tools.with_setup(None, common.cleanup)
143+
def test_rollback_table_multitablets():
144+
"""
145+
test table rollback w/multi tablets
146+
1. test_rollback_table_relaunch()
147+
:return:
148+
"""
149+
150+
common.createbyfile(schema=const.data_path + 'table.schema', deli=const.data_path + 'deli.10')
151+
test_rollback_table_relaunch()

0 commit comments

Comments
 (0)