File: misc.test.py

package info (click to toggle)
tarantool 1.7.2.385.g952d79e-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 21,556 kB
  • ctags: 28,405
  • sloc: ansic: 180,313; cpp: 26,044; sh: 15,513; python: 4,893; makefile: 1,412
file content (101 lines) | stat: -rw-r--r-- 2,469 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import os
import yaml

from os.path import abspath

# cleanup server.vardir
server.stop()
server.deploy()
lsn = int(yaml.load(server.admin("box.info.server.lsn", silent=True))[0])
server.stop()

data_path = os.path.join(server.vardir, server.name)

print """
# xlog file must exist after inserts.
"""
filename = str(lsn).zfill(20) + ".xlog"
wal = os.path.join(data_path, filename)

server.start()

server.admin("space = box.schema.space.create('tweedledum', { id = 0 })")
if os.access(wal, os.F_OK):
  print ".xlog exists"

server.admin("index = space:create_index('primary', { type = 'hash' })")

server.stop()
lsn += 2

print """
# a new xlog must be opened after regular termination.
"""
filename = str(lsn).zfill(20) + ".xlog"
server.start()

wal = os.path.join(data_path, filename)

server.admin("box.space[0]:insert{3, 'third tuple'}")

if os.access(wal, os.F_OK):
  print "a new .xlog exists"

server.stop()

if os.access(wal, os.F_OK):
  print ".xlog stays around after sutdown"
lsn += 1

print """
# An xlog file with one record during recovery.
"""

server.start()
filename = str(lsn).zfill(20) + ".xlog"
wal = os.path.join(data_path, filename)
server.admin("box.space[0]:insert{4, 'fourth tuple'}")
server.admin("box.space[0]:insert{5, 'Unfinished record'}")
pid = int(yaml.load(server.admin("require('tarantool').pid()", silent=True))[0])
from signal import SIGKILL
if pid > 0:
    os.kill(pid, SIGKILL)
server.stop()

if os.access(wal, os.F_OK):
    print ".xlog exists after kill -9"
    # Remove last byte from xlog
    f = open(wal, "a")
    size = f.tell()
    f.truncate(size - 1)
    f.close()

server.start()

if os.access(wal, os.F_OK):
  print "corrupt .xlog exists after start"
server.stop()
lsn += 1

server.start()
orig_lsn = int(yaml.load(admin("box.info.server.lsn", silent=True))[0])

# create .snap.inprogress
admin("box.snapshot()")
admin("box.space._schema:insert({'test', 'test'})")
admin("box.snapshot()")
lsn = int(yaml.load(admin("box.info.server.lsn", silent=True))[0])
snapshot = str(lsn).zfill(20) + ".snap"
snapshot = os.path.join(data_path, snapshot)
server.stop()
os.rename(snapshot, snapshot + ".inprogress")
# remove .xlogs
for f in os.listdir(data_path):
    if f.endswith(".xlog"):
        os.remove(os.path.join(data_path, f))

# check that .snap.inprogress is ignored during scan
server.start()
lsn = int(yaml.load(admin("box.info.server.lsn", silent=True))[0])
if lsn == orig_lsn:
    print ".snap.inprogress is ignored"