MySQL Forums
Forum List  »  Utilities

Had been building mysqlfabric using official document, using official test shard data script error.
Posted by: xinyuan wang
Date: June 30, 2016 04:24AM

Mysqlfabric throughout the build process is to use the official installation manual, mysql server version is5.7.13 for Linux - glibc2.5 (X86_64), mysql fabric version is 1.5.6, mysql connector - python version is 2.1.3-1. E16. X86_64. Python version is 2.6.6) does not appear in the process of building an error.In the use of official test the fragmented data fragmentation test script, and appear the error:

Traceback (most recent call last):
File "", line 95, in <module>
add_employee(conn, emp_no,first_names[emp_no % len(first_names)],last_names[emp_no % len(last_names)],gtid_executed)
File "", line 28, in add_employee
cur.execute("USE employees")
File "/usr/lib/python2.6/site-packages/mysql/connector/", line 515, in execute
File "/usr/lib/python2.6/site-packages/mysql/connector/fabric/", line 1608, in cmd_query
File "/usr/lib/python2.6/site-packages/mysql/connector/fabric/", line 1569, in handle_mysql_error
raise exc
mysql.connector.errors.ProgrammingError: 1049 (42000): Unknown database 'employees'

I looked at the library of employees in global group in the DB, however, employees in library not synchronized to the other two shard group.Why is this?
here is my profile:
import random
import mysql.connector
from mysql.connector import fabric

def prepare_synchronization(cur):
# We need to keep track of what we have executed so far to guarantee
# that the employees.employees table exists at all shards.
gtid_executed = None
cur.execute("SELECT @@global.gtid_executed")
for row in cur:
gtid_executed = row[0]
return gtid_executed

def synchronize(cur, gtid_executed):
# Guarantee that a slave has created the employees.employees table
# before reading anything.
(gtid_executed, )

def add_employee(conn, emp_no, first_name, last_name, gtid_executed):
conn.set_property(tables=["employees.employees"], key=emp_no,mode=fabric.MODE_READWRITE)
cur = conn.cursor()
synchronize(cur, gtid_executed)
print emp_no,first_name,last_name,gtid_executed
cur.execute("USE employees")
print "777777777777777"
"INSERT INTO employees VALUES (%s, %s, %s)",
(emp_no, first_name, last_name)

def find_employee(conn, emp_no, gtid_executed):
conn.set_property(tables=["employees.employees"], key=emp_no,
cur = conn.cursor()
synchronize(cur, gtid_executed)
cur.execute("USE employees")
for row in cur:
print "Had to synchronize", row, "transactions."
"SELECT first_name, last_name FROM employees "
"WHERE emp_no = %s", (emp_no, )
for row in cur:
print row

def pick_shard_key():
shard = random.randint(0, 2)
shard_range = shard * 100000
shard_range = shard_range if shard != 0 else shard_range + 1
shift_within_shard = random.randint(0, 99999)
return shard_range + shift_within_shard

# Address of the Fabric, not the host we are going to connect to.
conn = mysql.connector.connect(
fabric={"host" : "localhost", "port" : 32274,
"username": "admin", "password" : "admin"
user="fabric_server", password="wxy@123..", autocommit=True

conn.set_property(tables=["employees.employees"], scope=fabric.SCOPE_GLOBAL,
print "111111111111111111"
cur = conn.cursor()
cur.execute("CREATE DATABASE IF NOT EXISTS employees")
print "222222222222222222"
cur.execute("USE employees")
print "333333333333333333"
cur.execute("DROP TABLE IF EXISTS employees")
"CREATE TABLE employees ("
" emp_no INT, "
" first_name CHAR(40), "
" last_name CHAR(40)"
print "44444444444444444444"
gtid_executed = prepare_synchronization(cur)
print gtid_executed
print "55555555555555555555"
print "6666666666666666666"
first_names = ["John", "Buffalo", "Michael", "Kate", "Deep", "Genesis"]
last_names = ["Doe", "Bill", "Jackson", "Bush", "Purple"]
print last_names
list_emp_no = []
for count in range(10):
emp_no = pick_shard_key()
print emp_no
add_employee(conn, emp_no,first_names[emp_no % len(first_names)],last_names[emp_no % len(last_names)],gtid_executed)

for emp_no in list_emp_no:
print emp_no
find_employee(conn, emp_no, gtid_executed)

Options: ReplyQuote

Written By
Had been building mysqlfabric using official document, using official test shard data script error.
June 30, 2016 04:24AM

Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.