コード例 #1
0
ファイル: cluster.test.py プロジェクト: Frankie-666/tarantool
print '-------------------------------------------------------------'
print 'Start a new replica and check box.info on the start'
print '-------------------------------------------------------------'
# master server
master = server
master_id = master.get_param('server')['id']

master.admin("box.schema.user.grant('guest', 'replication')")

replica = TarantoolServer(server.ini)
replica.script = 'replication-py/replica.lua'
replica.vardir = server.vardir
replica.rpl_master = master
replica.deploy()
replica.wait_lsn(master_id, master.get_lsn(master_id))
replica_id = replica.get_param('server')['id']
replica_uuid = replica.get_param('server')['uuid']
sys.stdout.push_filter(replica_uuid, '<replica uuid>')

replica.admin('box.info.server.id == %d' % replica_id)
replica.admin('not box.info.server.ro')
replica.admin('box.info.server.lsn == 0')
replica.admin('box.info.vclock[%d] == 0' % replica_id)

print '-------------------------------------------------------------'
print 'Modify data to change LSN and check box.info'
print '-------------------------------------------------------------'
replica.admin('box.space._schema:insert{"test", 48}')
replica.admin('box.info.server.lsn == 1')
replica.admin('box.info.vclock[%d] == 1' % replica_id)
コード例 #2
0
            end;""", server2.id)
        print 'server', server.id, "connected"

print 'done'

print '----------------------------------------------------------------------'
print 'Test inserts'
print '----------------------------------------------------------------------'

print 'Create a test space'
master.admin("_ = box.schema.space.create('test')")
master.admin("_ = box.space.test:create_index('primary')")
master_lsn = master.get_lsn(master.id)
# Wait changes to propagate to replicas
for server in cluster:
    server.wait_lsn(master.id, master_lsn)
    print 'server', server.id, 'is ok'
print

print 'Insert records'
for i in range(ROW_N):
    server = cluster[i % REPLICA_N]
    server.admin("box.space.test:insert{%d, %s}" % (i, server.id), silent=True)
print 'inserted %d records' % ROW_N
print

print 'Synchronize'
for server1 in cluster:
    for server2 in cluster:
        server1.wait_lsn(server2.id, server2.get_lsn(server2.id))
    print 'server', server1.id, 'done'
コード例 #3
0
master.admin(
    "space = box.schema.space.create('test', { id = 99999, engine = \"sophia\" })"
)
master.admin("index = space:create_index('primary', { type = 'tree'})")
master.admin('for k = 1, 123 do space:insert{k, k*k} end')
master.admin('box.snapshot()')
lsn = master.get_lsn(master_id)

print '-------------------------------------------------------------'
print 'replica JOIN'
print '-------------------------------------------------------------'

# replica server
replica = TarantoolServer(server.ini)
replica.script = 'replication/replica.lua'
replica.vardir = server.vardir  #os.path.join(server.vardir,'replica')
replica.rpl_master = master
replica.deploy()
replica.wait_lsn(master_id, lsn)
replica.admin('box.space.test:select()')

replica.stop()
replica.cleanup(True)

# remove space
master.admin("space:drop()")
master.admin('box.snapshot()')
master.admin("ffi = require('ffi')")
master.admin("ffi.cdef(\"int sophia_schedule(void);\")")
master.admin("ffi.C.sophia_schedule() >= 0")
コード例 #4
0
ファイル: init_storage.test.py プロジェクト: bigbes/tarantool
replica.stop()
replica.cleanup(True)

master.admin('box.snapshot()')
master.restart()
master.admin('for k = 10, 19 do box.space[42]:insert{k, k*k*k} end')
lsn = master.get_param('lsn')
print '-------------------------------------------------------------'
print 'replica test 2 (must be ok)'
print '-------------------------------------------------------------'

replica = TarantoolServer(server.ini)
replica.cfgfile_source = 'replication/cfg/replica.cfg'
replica.vardir = os.path.join(server.vardir, 'replica')
replica.rpl_master = master
replica.deploy()

replica.admin('space = box.space.test');
replica.wait_lsn(lsn)
for i in range(1, 20):
    replica.admin('space:get{%d}' % i)

replica.stop()
replica.cleanup(True)

server.stop()
server.cfgfile_source = cfgfile_backup
server.deploy()

コード例 #5
0
ファイル: readonly.test.py プロジェクト: DarkDare/tarantool
import os
from glob import iglob as glob
from lib.tarantool_server import TarantoolServer

# master server
master = server
master_id = master.get_param('server')['id']

master.admin("box.schema.user.grant('guest', 'replication')")

replica = TarantoolServer(server.ini)
replica.script = 'replication/replica.lua'
replica.vardir = server.vardir #os.path.join(server.vardir, 'replica')
replica.rpl_master = master
replica.deploy()
replica.wait_lsn(master_id, master.get_lsn(master_id))
replica_id = replica.get_param('server')['id']
replica.admin('box.info.server.id')
replica.admin('box.info.server.ro')
replica.admin('box.info.server.lsn')
replica.stop()

print '-------------------------------------------------------------'
print 'replica is read-only until receive self server_id in _cluster'
print '-------------------------------------------------------------'

# Remove xlog retrived by SUBSCRIBE
filename = str(0).zfill(20) + ".xlog"
wal = os.path.join(os.path.join(replica.vardir, replica.name), filename)
os.remove(wal)
コード例 #6
0
"""
for i in range(id, id + 10):
    master_sql("insert into t0 values (%d, 'the tuple %d')" % (i, i))


print """
# Select 10 tuples from master
"""
for i in range(id, id + 10):
    master_sql("select * from t0 where k0 = %d" % i)


print """
# Select 10 tuples from replica
"""
replica.wait_lsn(11)
for i in range(id, id + 10):
    replica_sql("select * from t0 where k0 = %d" % i)


print """
# Shutdown master server (now the hot_standby must be a primary server)
"""
server.stop()

id += 10

# White while hot_standby server not bind masters ports
time.sleep(0.2)

print """
コード例 #7
0
ファイル: sophia_join.test.py プロジェクト: Mons/tarantool
master.admin("box.schema.user.grant('guest', 'replication')")
master.admin("space = box.schema.space.create('test', { id = 99999, engine = \"sophia\" })")
master.admin("index = space:create_index('primary', { type = 'tree'})")
master.admin('for k = 1, 123 do space:insert{k, k*k} end')
master.admin('box.snapshot()')
lsn = master.get_lsn(master_id)

print '-------------------------------------------------------------'
print 'replica JOIN'
print '-------------------------------------------------------------'

# replica server
replica = TarantoolServer(server.ini)
replica.script = 'replication/replica.lua'
replica.vardir = os.path.join(server.vardir, 'replica')
replica.rpl_master = master
replica.deploy()
replica.wait_lsn(master_id, lsn)
replica.admin('box.space.test:select()')

replica.stop()
replica.cleanup(True)

# remove space
master.admin("space:drop()")
master.admin('box.snapshot()')
master.admin("ffi = require('ffi')")
master.admin("ffi.cdef(\"int sophia_schedule(void);\")")
master.admin("ffi.C.sophia_schedule() >= 0")
コード例 #8
0
ファイル: memcached.test.py プロジェクト: catcher22/tarantool
replica_memcached("get 1 2 3 4 5 7 8 9 10\r\n")

print """# get deleted value"""
replica_memcached("get 6\r\n")

print """# flush all k-v on master and try to get them from replica"""
master_memcached("flush_all\r\n", silent=True)
wait_for_empty_space(replica)
replica_memcached("get 10\r\n")


print """# check that expiration is working properly on replica"""
master_memcached("set 1 0 1 %d\r\n%s\r\n" % (len(sonet[0]), sonet[0]), silent=True)
lsn = wait()
replica_memcached("get 1\r\n")
replica.wait_lsn(lsn + 1)
replica_memcached("get 1\r\n")

print """# check that expiration is working properly, when replica becomes master"""
master_memcached("set 1 0 1 %d\r\n%s\r\n" % (len(sonet[0]), sonet[0]), silent=True)
lsn = wait()
replica.reconfigure("replication/cfg/replica_to_master.cfg")
replica_memcached("get 1\r\n")
replica.wait_lsn(lsn + 1)
replica_memcached("get 1\r\n")


# restore default suite config
replica.stop()
replica.cleanup(True)
master.stop()
コード例 #9
0
ファイル: multi.test.py プロジェクト: daurnimator/tarantool
print 'Bootstrap replicas'
print '----------------------------------------------------------------------'

# Start replicas
master.id = master.get_param('server')['id']
master_lsn = master.get_lsn(master.id)
cluster = [ master ]
for i in range(REPLICA_N - 1):
    server = TarantoolServer(server.ini)
    server.script = 'replication/replica.lua'
    server.vardir = os.path.join(server.vardir, 'replica', str(master.id + i))
    server.rpl_master = master
    server.deploy()
    # Wait replica to fully bootstrap.
    # Otherwise can get ACCESS_DENIED error.
    server.wait_lsn(master.id, master_lsn)
    cluster.append(server)

# Make a list of servers
sources = []
for server in cluster:
    sources.append(yaml.load(server.admin('box.cfg.listen', silent = True))[0])
    server.id = server.get_param('server')['id']

print 'done'

print '----------------------------------------------------------------------'
print 'Make a full mesh'
print '----------------------------------------------------------------------'

# Connect each server to each other to make full mesh
コード例 #10
0
print """
# Insert 10 tuples to master
"""
for i in range(id, id + 10):
    master_sql("insert into t0 values (%d, 'the tuple %d')" % (i, i))

print """
# Select 10 tuples from master
"""
for i in range(id, id + 10):
    master_sql("select * from t0 where k0 = %d" % i)

print """
# Select 10 tuples from replica
"""
replica.wait_lsn(11)
for i in range(id, id + 10):
    replica_sql("select * from t0 where k0 = %d" % i)

print """
# Shutdown master server (now the hot_standby must be a primary server)
"""
server.stop()

id += 10

# White while hot_standby server not bind masters ports
time.sleep(0.2)

print """
# Insert 10 tuples to hot_standby