This commit is contained in:
shrutip 2014-03-27 15:36:52 -07:00
Родитель 8b6d6e03d8
Коммит 630b2fef07
3 изменённых файлов: 26 добавлений и 11 удалений

Просмотреть файл

@ -180,3 +180,9 @@ def get_host_port_by_name(topo_client, db_key, encrypted=False):
return encrypted_host_port_list return encrypted_host_port_list
random.shuffle(host_port_list) random.shuffle(host_port_list)
return host_port_list return host_port_list
def is_sharded_keyspace(keyspace_name, db_type):
ks = get_keyspace(keyspace_name)
shard_count = ks.get_shard_count(db_type)
return shard_count > 1

Просмотреть файл

@ -1,17 +1,23 @@
# Copyright 2012, Google Inc. All rights reserved. # Copyright 2012, Google Inc. All rights reserved.
# Use of this source code is governed by a BSD-style license that can # Use of this source code is governed by a BSD-style license that can
# be found in the LICENSE file. # be found in the LICENSE file.
import itertools import itertools
from vtdb import cursor from vtdb import cursor
from vtdb import dbexceptions from vtdb import dbexceptions
from vtdb import keyrange_constants
from vtdb import topology
write_sql_pattern = re.compile('\s*(insert|update|delete)', re.IGNORECASE) write_sql_pattern = re.compile('\s*(insert|update|delete)', re.IGNORECASE)
class __EmptyBindVariables(frozenset): class __EmptyBindVariables(frozenset):
pass pass
EmptyBindVariables = __EmptyBindVariables()
EmptyBindVariables = __EmptyBindVariables()
MAX_QUERY_SIZE = 32 * 1024 MAX_QUERY_SIZE = 32 * 1024
EXCESSIVE_BIND_VAR_COUNT = 1000 EXCESSIVE_BIND_VAR_COUNT = 1000
MAX_BIND_VAR_COUNT = 4000 MAX_BIND_VAR_COUNT = 4000
@ -73,12 +79,17 @@ class VTGateCursor(object):
if write_query: if write_query:
if not self.is_writable(): if not self.is_writable():
raise dbexceptions.DatabaseError('DML on a non-writable cursor', sql) raise dbexceptions.DatabaseError('DML on a non-writable cursor', sql)
# FIXME(shrutip): these checks maybe better on vtgate server.
if topology.is_sharded_keyspace(self.keyspace, self.tablet_type):
if keyspace_ids is None or len(keyspace_ids) != 1: if keyspace_ids is None or len(keyspace_ids) != 1:
raise dbexceptions.ProgrammingError('DML on zero or multiple keyspace ids is not allowed') raise dbexceptions.ProgrammingError('DML on zero or multiple keyspace ids is not allowed')
else: else:
# FIXME(shrutip): this could potentially be moved to vtgate server. if keyrange is None or keyrange != keyrange_constants.NON_PARTIAL_KEYRANGE:
sql += self._binlog_hint(keyspace_ids[0]) raise dbexceptions.ProgrammingError('Keyrange not correct for non-sharded keyspace')
# FIXME(shrutip): this could potentially be done on vtgate server.
sql += self._binlog_hint(keyspace_ids[0])
self.results, self.rowcount, self.lastrowid, self.description = self.connection._execute(sql, self.results, self.rowcount, self.lastrowid, self.description = self.connection._execute(sql,
bind_variables, bind_variables,

Просмотреть файл

@ -12,10 +12,6 @@ from vtdb import cursor
from vtdb import dbexceptions from vtdb import dbexceptions
from vtdb import field_types from vtdb import field_types
# This is the shard name for when the keyrange covers the entire space
# for unsharded database.
SHARD_ZERO = "0"
_errno_pattern = re.compile('\(errno (\d+)\)') _errno_pattern = re.compile('\(errno (\d+)\)')
# Map specific errors to specific classes. # Map specific errors to specific classes.
@ -23,8 +19,10 @@ _errno_map = {
1062: dbexceptions.IntegrityError, 1062: dbexceptions.IntegrityError,
} }
__error_counter_callback = None __error_counter_callback = None
def register_error_counter_callback(func): def register_error_counter_callback(func):
global __error_counter_callback global __error_counter_callback
__error_counter_callback = func __error_counter_callback = func