Skip to content
Closed
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
d77fbdf
modify comments keyspace
yangxuanjia Jan 11, 2018
02fbaf9
Merge remote-tracking branch 'upstream/master'
yangxuanjia Jan 12, 2018
576b541
modify comments keyspace
yangxuanjia Jan 12, 2018
b6bef33
Merge remote-tracking branch 'upstream/master'
yangxuanjia Jan 15, 2018
5c762ab
beauty
yangxuanjia Jan 15, 2018
6fc80de
Merge remote-tracking branch 'upstream/master'
yangxuanjia Jan 17, 2018
d9f1a53
Merge remote-tracking branch 'upstream/master'
yangxuanjia Jan 23, 2018
10cc035
Merge remote-tracking branch 'upstream/master'
yangxuanjia Jan 24, 2018
aeb7925
Merge remote-tracking branch 'upstream/master'
yangxuanjia Jan 24, 2018
3648e61
Merge remote-tracking branch 'upstream/master'
yangxuanjia Jan 25, 2018
0bcf43f
Merge remote-tracking branch 'upstream/master'
yangxuanjia Jan 26, 2018
1dfc597
Merge remote-tracking branch 'upstream/master'
yangxuanjia Jan 29, 2018
407f514
Merge remote-tracking branch 'upstream/master'
yangxuanjia Jan 30, 2018
284fdf7
Merge remote-tracking branch 'upstream/master'
yangxuanjia Feb 1, 2018
1d6ec9d
Merge remote-tracking branch 'upstream/master'
yangxuanjia Feb 2, 2018
f3e8c33
Merge remote-tracking branch 'upstream/master'
yangxuanjia Feb 6, 2018
8aaf9bb
Merge remote-tracking branch 'upstream/master'
yangxuanjia Feb 7, 2018
c44634b
Merge remote-tracking branch 'upstream/master'
yangxuanjia Feb 8, 2018
844bb51
when etcd all down , user can also connect vtgate
yangxuanjia Feb 8, 2018
2c656fd
when etcd all down , user can also connect vtgate
yangxuanjia Feb 8, 2018
5bb905c
when etcd all down , user can also connect vtgate
yangxuanjia Feb 8, 2018
79d74d8
when etcd all down , user can also connect vtgate
yangxuanjia Feb 8, 2018
2b79701
revert
yangxuanjia Feb 9, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions go/vt/discovery/tablet_stats_cache_wait_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,17 @@ func TestFindAllKeyspaceShards(t *testing.T) {
}

// Get it.
ks, err = FindAllTargets(ctx, rs, "cell1", []topodatapb.TabletType{topodatapb.TabletType_MASTER})
if err != nil {
t.Errorf("unexpected error: %v", err)
for {
ks, err = FindAllTargets(ctx, rs, "cell1", []topodatapb.TabletType{topodatapb.TabletType_MASTER})
if err != nil {
t.Errorf("unexpected error: %v", err)
}
if ks != nil {
break
}
time.Sleep(time.Millisecond)
}

if !reflect.DeepEqual(ks, []*querypb.Target{
{
Cell: "cell1",
Expand Down
72 changes: 35 additions & 37 deletions go/vt/srvtopo/resilient_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,53 +207,51 @@ func (server *ResilientServer) GetSrvKeyspaceNames(ctx context.Context, cell str
}
server.mutex.Unlock()

// Lock the entry, and do everything holding the lock. This
// means two concurrent requests will only issue one
// underlying query.
entry.mutex.Lock()
defer entry.mutex.Unlock()

// If it is not time to check again, then return either the cached
// value or the cached error
cacheValid := entry.value != nil && time.Since(entry.insertionTime) < server.cacheTTL

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can't access any value inside entry if you don't have the entry.mutex.Lock()...

shouldRefresh := time.Since(entry.lastQueryTime) > server.cacheRefresh

if !shouldRefresh {
if cacheValid {
return entry.value, nil
}
return nil, entry.lastError
if !shouldRefresh && cacheValid {
return entry.value, nil
}

// Not in cache or needs refresh so try to get the real value.
// We use the context that issued the query here.
result, err := server.topoServer.GetSrvKeyspaceNames(ctx, cell)
if err == nil {
// save the value we got and the current time in the cache
entry.insertionTime = time.Now()
entry.value = result
} else {
if entry.insertionTime.IsZero() {
server.counts.Add(errorCategory, 1)
log.Errorf("GetSrvKeyspaceNames(%v, %v) failed: %v (no cached value, caching and returning error)", ctx, cell, err)

} else if cacheValid {
server.counts.Add(cachedCategory, 1)
log.Warningf("GetSrvKeyspaceNames(%v, %v) failed: %v (returning cached value: %v %v)", ctx, cell, err, entry.value, entry.lastError)
result = entry.value
err = nil
go func() {
// Lock the entry, and do everything holding the lock. This
// means two concurrent requests will only issue one
// underlying query.
entry.mutex.Lock()
defer entry.mutex.Unlock()

if entry.value != nil && time.Since(entry.insertionTime) < server.cacheTTL {
return
}

// Not in cache or needs refresh so try to get the real value.
// We use the context that issued the query here.
result, err := server.topoServer.GetSrvKeyspaceNames(ctx, cell)
if err == nil {
// save the value we got and the current time in the cache
entry.insertionTime = time.Now()
entry.value = result
} else {
server.counts.Add(errorCategory, 1)
log.Errorf("GetSrvKeyspaceNames(%v, %v) failed: %v (cached value expired)", ctx, cell, err)
entry.insertionTime = time.Time{}
entry.value = nil
if entry.insertionTime.IsZero() {
server.counts.Add(errorCategory, 1)
log.Errorf("GetSrvKeyspaceNames(%v, %v) failed: %v (no cached value, caching and returning error)", ctx, cell, err)
} else if cacheValid {
server.counts.Add(cachedCategory, 1)
log.Warningf("GetSrvKeyspaceNames(%v, %v) failed: %v (returning cached value: %v %v)", ctx, cell, err, entry.value, entry.lastError)
} else {
server.counts.Add(errorCategory, 1)
log.Errorf("GetSrvKeyspaceNames(%v, %v) failed: %v (cached value expired, but also returning cached value: %v %v)", ctx, cell, err, entry.value, entry.lastError)
}
}
}
entry.lastError = err
entry.lastQueryTime = time.Now()
entry.lastErrorCtx = ctx
}()

entry.lastError = err
entry.lastQueryTime = time.Now()
entry.lastErrorCtx = ctx
return result, err
return entry.value, entry.lastError
}

func (server *ResilientServer) getSrvKeyspaceEntry(cell, keyspace string) *srvKeyspaceEntry {
Expand Down
16 changes: 13 additions & 3 deletions go/vt/srvtopo/resilient_server_flaky_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -394,10 +394,20 @@ func TestGetSrvKeyspaceNames(t *testing.T) {
ts.UpdateSrvKeyspace(context.Background(), "test_cell", "test_ks2", want)

ctx := context.Background()
names, err := rs.GetSrvKeyspaceNames(ctx, "test_cell")
if err != nil {
t.Errorf("GetSrvKeyspaceNames unexpected error %v", err)

var names []string
var err error
for {
names, err = rs.GetSrvKeyspaceNames(ctx, "test_cell")
if err != nil {
t.Errorf("GetSrvKeyspaceNames unexpected error %v", err)
}
if names != nil {
break
}
time.Sleep(time.Millisecond)
}

wantNames := []string{"test_ks", "test_ks2"}

if !reflect.DeepEqual(names, wantNames) {
Expand Down
2 changes: 1 addition & 1 deletion go/vt/vtgate/vindexes/lookup_internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ func (lkp *lookupInternal) Create(vcursor VCursor, rowsColValues [][]sqltypes.Va
//
// Given the following information in a vindex table with two columns:
//
// +------------------+-----------+--------+
// +------------------+-----------+--------+
// | hex(keyspace_id) | a | b |
// +------------------+-----------+--------+
// | 52CB7B1B31B2222E | valuea | valueb |
Expand Down
4 changes: 2 additions & 2 deletions go/vt/vtgate/vindexes/vschema.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ type Table struct {
Pinned []byte `json:"pinned,omitempty"`
}

// Keyspace contains the keyspcae info for each Table.
// Keyspace contains the keyspace info for each Table.
type Keyspace struct {
Name string
Sharded bool
Expand Down Expand Up @@ -404,7 +404,7 @@ func (vschema *VSchema) FindTableOrVindex(keyspace, name string) (*Table, Vindex
}

// FindVindex finds a vindex by name. If a keyspace is specified, only vindexes
// from that keyspace are searched. If no kesypace is specified, then a vindex
// from that keyspace are searched. If no keyspace is specified, then a vindex
// is returned only if its name is unique across all keyspaces. The function
// returns an error only if the vindex name is ambiguous.
func (vschema *VSchema) FindVindex(keyspace, name string) (Vindex, error) {
Expand Down