from __future__ import print_function

import os
import yaml
#
# gh-167: Replica can't find next xlog file if there is a gap in LSN
#

server.stop()
server.deploy()

# Create wal#1
server.admin("space = box.schema.space.create('test')")
server.admin("index = box.space.test:create_index('primary')")
server.admin("box.space.test:insert{1, 'first tuple'}")
server.admin("box.space.test:insert{2, 'second tuple'}")
lsn = int(yaml.safe_load(server.admin("box.info.lsn", silent=True))[0])
path = os.path.join(server.vardir, server.name)
wal = os.path.join(path, str(lsn).zfill(20) + ".xlog")
server.stop()
server.start()
server.admin("box.space.test:insert{3, 'third tuple'}")
server.stop()
server.start()
server.admin("box.space.test:insert{4, 'fourth tuple'}")
server.stop()

# Remove xlog with {3, 'third tuple'}
os.unlink(wal)

server.start()
line="ignoring a gap in LSN"
print("check log line for '{}'".format(line))
print("")
if server.logfile_pos.seek_once(line) >= 0:
    print("'{}' exists in server log".format(line))
print("")

# missing tuple from removed xlog
server.admin("box.space.test:select{}")

5876fb66f537d9ef8f410a3d0bb725e0a1b71544
<mask token>

<mask token>
server.stop()
server.deploy()
server.admin("space = box.schema.space.create('test')")
server.admin("index = box.space.test:create_index('primary')")
server.admin("box.space.test:insert{1, 'first tuple'}")
server.admin("box.space.test:insert{2, 'second tuple'}")
<mask token>
server.stop()
server.start()
server.admin("box.space.test:insert{3, 'third tuple'}")
server.stop()
server.start()
server.admin("box.space.test:insert{4, 'fourth tuple'}")
server.stop()
os.unlink(wal)
server.start()
<mask token>
print("check log line for '{}'".format(line))
print('')
if server.logfile_pos.seek_once(line) >= 0:
    print("'{}' exists in server log".format(line))
print('')
server.admin('box.space.test:select{}')

<mask token>
server.stop()
server.deploy()
server.admin("space = box.schema.space.create('test')")
server.admin("index = box.space.test:create_index('primary')")
server.admin("box.space.test:insert{1, 'first tuple'}")
server.admin("box.space.test:insert{2, 'second tuple'}")
lsn = int(yaml.safe_load(server.admin('box.info.lsn', silent=True))[0])
path = os.path.join(server.vardir, server.name)
wal = os.path.join(path, str(lsn).zfill(20) + '.xlog')
server.stop()
server.start()
server.admin("box.space.test:insert{3, 'third tuple'}")
server.stop()
server.start()
server.admin("box.space.test:insert{4, 'fourth tuple'}")
server.stop()
os.unlink(wal)
server.start()
line = 'ignoring a gap in LSN'
print("check log line for '{}'".format(line))
print('')
if server.logfile_pos.seek_once(line) >= 0:
    print("'{}' exists in server log".format(line))
print('')
server.admin('box.space.test:select{}')

from __future__ import print_function
import os
import yaml
server.stop()
server.deploy()
server.admin("space = box.schema.space.create('test')")
server.admin("index = box.space.test:create_index('primary')")
server.admin("box.space.test:insert{1, 'first tuple'}")
server.admin("box.space.test:insert{2, 'second tuple'}")
lsn = int(yaml.safe_load(server.admin('box.info.lsn', silent=True))[0])
path = os.path.join(server.vardir, server.name)
wal = os.path.join(path, str(lsn).zfill(20) + '.xlog')
server.stop()
server.start()
server.admin("box.space.test:insert{3, 'third tuple'}")
server.stop()
server.start()
server.admin("box.space.test:insert{4, 'fourth tuple'}")
server.stop()
os.unlink(wal)
server.start()
line = 'ignoring a gap in LSN'
print("check log line for '{}'".format(line))
print('')
if server.logfile_pos.seek_once(line) >= 0:
    print("'{}' exists in server log".format(line))
print('')
server.admin('box.space.test:select{}')

from __future__ import print_function

import os
import yaml
#
# gh-167: Replica can't find next xlog file if there is a gap in LSN
#

server.stop()
server.deploy()

# Create wal#1
server.admin("space = box.schema.space.create('test')")
server.admin("index = box.space.test:create_index('primary')")
server.admin("box.space.test:insert{1, 'first tuple'}")
server.admin("box.space.test:insert{2, 'second tuple'}")
lsn = int(yaml.safe_load(server.admin("box.info.lsn", silent=True))[0])
path = os.path.join(server.vardir, server.name)
wal = os.path.join(path, str(lsn).zfill(20) + ".xlog")
server.stop()
server.start()
server.admin("box.space.test:insert{3, 'third tuple'}")
server.stop()
server.start()
server.admin("box.space.test:insert{4, 'fourth tuple'}")
server.stop()

# Remove xlog with {3, 'third tuple'}
os.unlink(wal)

server.start()
line="ignoring a gap in LSN"
print("check log line for '{}'".format(line))
print("")
if server.logfile_pos.seek_once(line) >= 0:
    print("'{}' exists in server log".format(line))
print("")

# missing tuple from removed xlog
server.admin("box.space.test:select{}")
