Merge branch 'master' into suguwork

This commit is contained in:
Sugu Sougoumarane 2016-03-01 12:59:31 -08:00
Родитель 51f6d7bff5 9fff2891ba
Коммит eaa6565bab
12 изменённых файлов: 113 добавлений и 38 удалений

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

@ -15,6 +15,8 @@ source $script_root/env.sh
# Pass a list of UID indices on the command line to override.
uids=${@:-'0 1 2'}
wait_pids=''
for uid_index in $uids; do
uid=$[$uid_base + $uid_index]
printf -v alias '%s-%010d' $cell $uid
@ -23,12 +25,18 @@ for uid_index in $uids; do
echo "Stopping vttablet for $alias..."
pid=`cat $VTDATAROOT/$tablet_dir/vttablet.pid`
kill $pid
while ps -p $pid > /dev/null; do sleep 1; done
wait_pids="$wait_pids $pid"
echo "Stopping MySQL for tablet $alias..."
$VTROOT/bin/mysqlctl \
-db-config-dba-uname vt_dba \
-tablet_uid $uid \
shutdown
shutdown &
done
# Wait for vttablets to die.
while ps -p $wait_pids > /dev/null; do sleep 1; done
# Wait for 'mysqlctl shutdown' commands to finish.
wait

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

@ -63,10 +63,9 @@ fi
# Pass a list of UID indices on the command line to override.
uids=${@:-'0 1 2'}
# Start all mysqlds in background.
for uid_index in $uids; do
uid=$[$uid_base + $uid_index]
port=$[$port_base + $uid_index]
grpc_port=$[$grpc_port_base + $uid_index]
mysql_port=$[$mysql_port_base + $uid_index]
printf -v alias '%s-%010d' $cell $uid
printf -v tablet_dir 'vt_%010d' $uid
@ -82,7 +81,19 @@ for uid_index in $uids; do
-log_dir $VTDATAROOT/tmp \
-tablet_uid $uid $dbconfig_flags \
-mysql_port $mysql_port \
$action
$action &
done
# Wait for all mysqld to start up.
wait
# Start all vttablets in background.
for uid_index in $uids; do
uid=$[$uid_base + $uid_index]
port=$[$port_base + $uid_index]
grpc_port=$[$grpc_port_base + $uid_index]
printf -v alias '%s-%010d' $cell $uid
printf -v tablet_dir 'vt_%010d' $uid
echo "Starting vttablet for $alias..."
$VTROOT/bin/vttablet \

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

@ -8,7 +8,8 @@ import (
)
var (
lowReplicationLag = flag.Duration("discovery_low_replication_lag", 30*time.Second, "the replication lag that is considered low enough to be healthy")
// LowReplicationLag defines the duration that replication lag is low enough that the VTTablet is considered healthy.
LowReplicationLag = flag.Duration("discovery_low_replication_lag", 30*time.Second, "the replication lag that is considered low enough to be healthy")
highReplicationLagMinServing = flag.Duration("discovery_high_replication_lag_minimum_serving", 2*time.Hour, "the replication lag that is considered too high when selecting miminum 2 vttablets for serving")
)
@ -34,7 +35,7 @@ func FilterByReplicationLag(epsList []*EndPointStats) []*EndPointStats {
// if all have low replication lag (<=30s), return all endpoints.
allLowLag := true
for _, eps := range list {
if float64(eps.Stats.SecondsBehindMaster) > lowReplicationLag.Seconds() {
if float64(eps.Stats.SecondsBehindMaster) > LowReplicationLag.Seconds() {
allLowLag = false
break
}

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

@ -192,7 +192,7 @@ func (ts Server) UpdateKeyspace(ctx context.Context, ki *KeyspaceInfo) error {
func (ts Server) FindAllShardsInKeyspace(ctx context.Context, keyspace string) (map[string]*ShardInfo, error) {
shards, err := ts.GetShardNames(ctx, keyspace)
if err != nil {
return nil, err
return nil, fmt.Errorf("failed to get list of shards for keyspace '%v': %v", keyspace, err)
}
result := make(map[string]*ShardInfo, len(shards))

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

@ -115,7 +115,7 @@ func keyspacesWithOverlappingShards(ctx context.Context, wr *wrangler.Wrangler)
keyspaces, err := wr.TopoServer().GetKeyspaces(shortCtx)
cancel()
if err != nil {
return nil, err
return nil, fmt.Errorf("failed to get list of keyspaces: %v", err)
}
wg := sync.WaitGroup{}

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

@ -84,7 +84,7 @@ func shardsWithSources(ctx context.Context, wr *wrangler.Wrangler) ([]map[string
keyspaces, err := wr.TopoServer().GetKeyspaces(shortCtx)
cancel()
if err != nil {
return nil, err
return nil, fmt.Errorf("failed to get list of keyspaces: %v", err)
}
wg := sync.WaitGroup{}
@ -99,7 +99,7 @@ func shardsWithSources(ctx context.Context, wr *wrangler.Wrangler) ([]map[string
shards, err := wr.TopoServer().GetShardNames(shortCtx, keyspace)
cancel()
if err != nil {
rec.RecordError(err)
rec.RecordError(fmt.Errorf("failed to get list of shards for keyspace '%v': %v", keyspace, err))
return
}
for _, shard := range shards {
@ -110,7 +110,7 @@ func shardsWithSources(ctx context.Context, wr *wrangler.Wrangler) ([]map[string
si, err := wr.TopoServer().GetShard(shortCtx, keyspace, shard)
cancel()
if err != nil {
rec.RecordError(err)
rec.RecordError(fmt.Errorf("failed to get details for shard '%v': %v", topoproto.KeyspaceShardString(keyspace, shard), err))
return
}
@ -132,7 +132,7 @@ func shardsWithSources(ctx context.Context, wr *wrangler.Wrangler) ([]map[string
return nil, rec.Error()
}
if len(result) == 0 {
return nil, fmt.Errorf("There are no shards with SourceShards")
return nil, fmt.Errorf("there are no shards with SourceShards")
}
return result, nil
}

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

@ -115,7 +115,7 @@ func keyspacesWithServedFrom(ctx context.Context, wr *wrangler.Wrangler) ([]stri
keyspaces, err := wr.TopoServer().GetKeyspaces(shortCtx)
cancel()
if err != nil {
return nil, err
return nil, fmt.Errorf("failed to get list of keyspaces: %v", err)
}
wg := sync.WaitGroup{}
@ -130,7 +130,7 @@ func keyspacesWithServedFrom(ctx context.Context, wr *wrangler.Wrangler) ([]stri
ki, err := wr.TopoServer().GetKeyspace(shortCtx, keyspace)
cancel()
if err != nil {
rec.RecordError(err)
rec.RecordError(fmt.Errorf("failed to get details for keyspace '%v': %v", keyspace, err))
return
}
if len(ki.ServedFroms) > 0 {
@ -146,7 +146,7 @@ func keyspacesWithServedFrom(ctx context.Context, wr *wrangler.Wrangler) ([]stri
return nil, rec.Error()
}
if len(result) == 0 {
return nil, fmt.Errorf("There are no keyspaces with ServedFrom")
return nil, fmt.Errorf("there are no keyspaces with ServedFrom")
}
return result, nil
}

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

@ -75,7 +75,7 @@ func shardsWithTablesSources(ctx context.Context, wr *wrangler.Wrangler) ([]map[
keyspaces, err := wr.TopoServer().GetKeyspaces(shortCtx)
cancel()
if err != nil {
return nil, err
return nil, fmt.Errorf("failed to get list of keyspaces: %v", err)
}
wg := sync.WaitGroup{}
@ -90,7 +90,7 @@ func shardsWithTablesSources(ctx context.Context, wr *wrangler.Wrangler) ([]map[
shards, err := wr.TopoServer().GetShardNames(shortCtx, keyspace)
cancel()
if err != nil {
rec.RecordError(err)
rec.RecordError(fmt.Errorf("failed to get list of shards for keyspace '%v': %v", keyspace, err))
return
}
for _, shard := range shards {
@ -101,7 +101,7 @@ func shardsWithTablesSources(ctx context.Context, wr *wrangler.Wrangler) ([]map[
si, err := wr.TopoServer().GetShard(shortCtx, keyspace, shard)
cancel()
if err != nil {
rec.RecordError(err)
rec.RecordError(fmt.Errorf("failed to get details for shard '%v': %v", topoproto.KeyspaceShardString(keyspace, shard), err))
return
}
@ -123,7 +123,7 @@ func shardsWithTablesSources(ctx context.Context, wr *wrangler.Wrangler) ([]map[
return nil, rec.Error()
}
if len(result) == 0 {
return nil, fmt.Errorf("There are no shards with SourceShards")
return nil, fmt.Errorf("there are no shards with SourceShards")
}
return result, nil
}

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

@ -53,8 +53,8 @@ public class VitessClientExample {
System.out.println("Inserting into master...");
VTGateTx tx = conn.begin(ctx).checkedGet();
tx.executeShards(ctx, "INSERT INTO test_table (msg) VALUES (:msg)", keyspace, shards,
bindVars, TabletType.MASTER);
tx.commit(ctx);
bindVars, TabletType.MASTER).checkedGet();
tx.commit(ctx).checkedGet();
// Read it back from the master.
System.out.println("Reading from master...");

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

@ -1,5 +1,4 @@
<?php
namespace Vitess;
use Vitess\Proto\Vtrpc\ErrorCode;
@ -19,7 +18,10 @@ class ProtoUtils
{
/**
* @param $response
* Throws the appropriate exception for the "partial error" in a response.
*
* @param mixed $response
* any protobuf response message that may have a "partial error"
*
* @throws Error\BadInput
* @throws Error\DeadlineExceeded
@ -52,6 +54,7 @@ class ProtoUtils
}
/**
*
* @param string $query
* @param array $vars
*
@ -74,6 +77,7 @@ class ProtoUtils
}
/**
*
* @param mixed $value
*
* @return Query\BindVariable
@ -154,6 +158,7 @@ class ProtoUtils
}
/**
*
* @param mixed $proto
* @param array $queries
*/
@ -165,6 +170,7 @@ class ProtoUtils
}
/**
*
* @param string $hex
*
* @return string
@ -175,6 +181,7 @@ class ProtoUtils
}
/**
*
* @param string $start
* @param string $end
*
@ -189,6 +196,7 @@ class ProtoUtils
}
/**
*
* @param mixed $proto
* @param array $key_ranges
*/
@ -200,6 +208,7 @@ class ProtoUtils
}
/**
*
* @param string $keyspace_id
* @param mixed $value
*
@ -219,6 +228,7 @@ class ProtoUtils
}
/**
*
* @param mixed $proto
* @param array $entity_keyspace_ids
*/
@ -230,10 +240,11 @@ class ProtoUtils
}
/**
*
* @param string $query
* @param $bind_vars
* @param mixed $bind_vars
* @param string $keyspace
* @param $shards
* @param mixed $shards
*
* @return BoundShardQuery
*/
@ -247,10 +258,11 @@ class ProtoUtils
}
/**
*
* @param string $query
* @param $bind_vars
* @param mixed $bind_vars
* @param string $keyspace
* @param $keyspace_ids
* @param mixed $keyspace_ids
*
* @return BoundKeyspaceIdQuery
*/
@ -264,6 +276,7 @@ class ProtoUtils
}
/**
*
* @param Query\Row $row
* @param Query\Field[] $fields
*
@ -278,20 +291,25 @@ class ProtoUtils
// See the docs for the Row message in query.proto.
$start = 0;
$buf = $row->getValues();
$buflen = strlen($buf);
$lengths = $row->getLengths();
foreach ($lengths as $key => $len) {
$fieldKey = $fields[$key]->getName();
$val = null;
if ($len < 0) {
// This indicates a MySQL NULL value,
// to distinguish it from a zero-length string.
$val = NULL;
} else {
$val = substr($buf, $start, $len);
if ($val === FALSE || strlen($val) !== $len) {
throw new Exception('Index out of bounds while decoding Row values');
// $len < 0 indicates a MySQL NULL value,
// to distinguish it from a zero-length string.
$val = null;
if ($len >= 0) {
if ($start == $buflen) {
// Different PHP versions treat this case differently in
// substr(), so we handle it manually.
$val = '';
} else {
$val = substr($buf, $start, $len);
if ($val === FALSE || strlen($val) !== $len) {
throw new Exception("Index out of bounds while decoding Row values (start=$start, len=$len). Raw protobuf: " . var_export($row, TRUE));
}
}
$start += $len;

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

@ -61,4 +61,34 @@ class ProtoUtilsTest extends \PHPUnit_Framework_TestCase
$this->assertEquals($expected, $actual);
}
}
public function testRowValues()
{
$row = new Proto\Query\Row();
$row->setValues('onethree');
$row->setLengths([
3,
- 1, // MySQL NULL
5,
0
]);
$fields = [
make_field('c1'),
make_field('c2'),
make_field('c3'),
make_field('c4')
];
$expected = [
0 => 'one',
1 => null,
2 => 'three',
3 => '',
'c1' => 'one',
'c2' => null,
'c3' => 'three',
'c4' => ''
];
$actual = ProtoUtils::RowValues($row, $fields);
$this->assertEquals($expected, $actual);
}
}

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

@ -27,3 +27,10 @@ function add_list_bind_var($bound_query, $type, $key, $values)
$entry->setValue($bv);
$bound_query->addBindVariables($entry);
}
function make_field($name)
{
$field = new Proto\Query\Field();
$field->setName($name);
return $field;
}