From 9bf6bd5f5fdaf53538e6bbf6d3e9aa13a7d745a5 Mon Sep 17 00:00:00 2001 From: Shlomi Noach Date: Thu, 13 Sep 2018 14:52:12 +0300 Subject: [PATCH 1/9] WIP: adding API endpoint: 'ks-hostnames' --- go/vt/vtctld/api.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/go/vt/vtctld/api.go b/go/vt/vtctld/api.go index 645a14bec31..f098686ff83 100644 --- a/go/vt/vtctld/api.go +++ b/go/vt/vtctld/api.go @@ -169,6 +169,14 @@ func initAPI(ctx context.Context, ts *topo.Server, actions *ActionRepository, re } }) + handleConnection("ks-tablets", func(r *http.Request) (interface{}, error) { + shardNames, err := ts.GetShardNames(ctx, keyspace) + if err != nil { + return err + } + + }) + // Shards handleCollection("shards", func(r *http.Request) (interface{}, error) { shardPath := getItemPath(r.URL.Path) From e6072d295a9a795646f402041f1d0cd3ffca3877 Mon Sep 17 00:00:00 2001 From: Shlomi Noach Date: Thu, 13 Sep 2018 14:59:12 +0300 Subject: [PATCH 2/9] returning array of hostnames --- go/vt/vtctld/api.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/go/vt/vtctld/api.go b/go/vt/vtctld/api.go index f098686ff83..b5b33f3cdf6 100644 --- a/go/vt/vtctld/api.go +++ b/go/vt/vtctld/api.go @@ -170,9 +170,10 @@ func initAPI(ctx context.Context, ts *topo.Server, actions *ActionRepository, re }) handleConnection("ks-tablets", func(r *http.Request) (interface{}, error) { + hostnames := []string{} shardNames, err := ts.GetShardNames(ctx, keyspace) if err != nil { - return err + return hostnames, err } }) From 817cafcbdaf00ed1cba5232a28a7c6552cf97342 Mon Sep 17 00:00:00 2001 From: Shlomi Noach Date: Thu, 13 Sep 2018 15:02:35 +0300 Subject: [PATCH 3/9] ongoing --- go/vt/vtctld/api.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/go/vt/vtctld/api.go b/go/vt/vtctld/api.go index b5b33f3cdf6..10c78e0816a 100644 --- a/go/vt/vtctld/api.go +++ b/go/vt/vtctld/api.go @@ -169,13 +169,20 @@ func initAPI(ctx context.Context, ts *topo.Server, actions *ActionRepository, re } }) - handleConnection("ks-tablets", func(r *http.Request) (interface{}, error) { + handleCollection("ks-tablets", func(r *http.Request) (interface{}, error) { hostnames := []string{} + + keyspace := getItemPath(r.URL.Path) + if keyspace == "" { + return nil, errors.New("keyspace is required") + } shardNames, err := ts.GetShardNames(ctx, keyspace) if err != nil { return hostnames, err } - + for _, shard := range shardNames { + // Get tables for this shard. + } }) // Shards From 2e705fb5c02d647f3fd767119f6bfaef068d620f Mon Sep 17 00:00:00 2001 From: Shlomi Noach Date: Thu, 13 Sep 2018 15:12:45 +0300 Subject: [PATCH 4/9] feature complete --- go/vt/vtctld/api.go | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/go/vt/vtctld/api.go b/go/vt/vtctld/api.go index 10c78e0816a..a55e932ad24 100644 --- a/go/vt/vtctld/api.go +++ b/go/vt/vtctld/api.go @@ -169,8 +169,7 @@ func initAPI(ctx context.Context, ts *topo.Server, actions *ActionRepository, re } }) - handleCollection("ks-tablets", func(r *http.Request) (interface{}, error) { - hostnames := []string{} + handleCollection("ks_tablets", func(r *http.Request) (interface{}, error) { keyspace := getItemPath(r.URL.Path) if keyspace == "" { @@ -178,11 +177,27 @@ func initAPI(ctx context.Context, ts *topo.Server, actions *ActionRepository, re } shardNames, err := ts.GetShardNames(ctx, keyspace) if err != nil { - return hostnames, err + return nil, err } + + tablets := [](*topodatapb.Tablet){} + for _, shard := range shardNames { // Get tables for this shard. + tabletAliases, err := ts.FindAllTabletAliasesInShard(ctx, keyspace, shard) + if err != nil && !topo.IsErrType(err, topo.PartialResult) { + return result, err + } + for _, tabletAlias := range tabletAliases { + t, err := ts.GetTablet(ctx, tabletAlias) + if err != nil { + return nil, err + } + tablets = append(tablets, t.Tablet) + } } + + return tablets, nil }) // Shards From 15c0594950a24c62627fb85b5699e5f807a9ee32 Mon Sep 17 00:00:00 2001 From: Shlomi Noach Date: Thu, 13 Sep 2018 15:14:08 +0300 Subject: [PATCH 5/9] typo param name --- go/vt/vtctld/api.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go/vt/vtctld/api.go b/go/vt/vtctld/api.go index a55e932ad24..de08ad592d6 100644 --- a/go/vt/vtctld/api.go +++ b/go/vt/vtctld/api.go @@ -186,7 +186,7 @@ func initAPI(ctx context.Context, ts *topo.Server, actions *ActionRepository, re // Get tables for this shard. tabletAliases, err := ts.FindAllTabletAliasesInShard(ctx, keyspace, shard) if err != nil && !topo.IsErrType(err, topo.PartialResult) { - return result, err + return nil, err } for _, tabletAlias := range tabletAliases { t, err := ts.GetTablet(ctx, tabletAlias) From efd8e745fa0a8349fc610a3002e6208ea704852f Mon Sep 17 00:00:00 2001 From: Shlomi Noach Date: Sun, 16 Sep 2018 08:30:10 +0300 Subject: [PATCH 6/9] optionally provide explicit shard --- go/vt/vtctld/api.go | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/go/vt/vtctld/api.go b/go/vt/vtctld/api.go index de08ad592d6..94312238555 100644 --- a/go/vt/vtctld/api.go +++ b/go/vt/vtctld/api.go @@ -170,14 +170,25 @@ func initAPI(ctx context.Context, ts *topo.Server, actions *ActionRepository, re }) handleCollection("ks_tablets", func(r *http.Request) (interface{}, error) { + // Valid requests: api/ks_tables/my_ks (all shards) + // Valid requests: api/ks_tables/my_ks/-80 (specific shard) + itemPath := getItemPath(r.URL.Path) + parts := strings.SplitN(shardPath, "/", 2) - keyspace := getItemPath(r.URL.Path) + keyspace := parts[0] if keyspace == "" { return nil, errors.New("keyspace is required") } - shardNames, err := ts.GetShardNames(ctx, keyspace) - if err != nil { - return nil, err + + var shardNames []string + if len(parts) > 1 { + shardNames = []string{parts[1]} + } else { + var err error + shardNames, err = ts.GetShardNames(ctx, keyspace) + if err != nil { + return nil, err + } } tablets := [](*topodatapb.Tablet){} From a0821c63557d57df05cc2140e3ccceaabac1eaa7 Mon Sep 17 00:00:00 2001 From: Shlomi Noach Date: Sun, 16 Sep 2018 08:32:57 +0300 Subject: [PATCH 7/9] compilation error --- go/vt/vtctld/api.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go/vt/vtctld/api.go b/go/vt/vtctld/api.go index 94312238555..b05de39e2e8 100644 --- a/go/vt/vtctld/api.go +++ b/go/vt/vtctld/api.go @@ -173,7 +173,7 @@ func initAPI(ctx context.Context, ts *topo.Server, actions *ActionRepository, re // Valid requests: api/ks_tables/my_ks (all shards) // Valid requests: api/ks_tables/my_ks/-80 (specific shard) itemPath := getItemPath(r.URL.Path) - parts := strings.SplitN(shardPath, "/", 2) + parts := strings.SplitN(itemPath, "/", 2) keyspace := parts[0] if keyspace == "" { From 9029e31808d020bbc91f58efb834e8a4225a6e33 Mon Sep 17 00:00:00 2001 From: Shlomi Noach Date: Sun, 16 Sep 2018 09:03:29 +0300 Subject: [PATCH 8/9] allow trailing slash --- go/vt/vtctld/api.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go/vt/vtctld/api.go b/go/vt/vtctld/api.go index b05de39e2e8..52fa3ce247c 100644 --- a/go/vt/vtctld/api.go +++ b/go/vt/vtctld/api.go @@ -181,7 +181,7 @@ func initAPI(ctx context.Context, ts *topo.Server, actions *ActionRepository, re } var shardNames []string - if len(parts) > 1 { + if len(parts) > 1 && parts[1] != "" { shardNames = []string{parts[1]} } else { var err error From 62cf1c18d8d5dc0e2eff1abf8279da3367776d47 Mon Sep 17 00:00:00 2001 From: Shlomi Noach Date: Tue, 18 Sep 2018 12:44:11 +0300 Subject: [PATCH 9/9] typo --- go/vt/vtctld/api.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go/vt/vtctld/api.go b/go/vt/vtctld/api.go index 52fa3ce247c..f6e4148623d 100644 --- a/go/vt/vtctld/api.go +++ b/go/vt/vtctld/api.go @@ -194,7 +194,7 @@ func initAPI(ctx context.Context, ts *topo.Server, actions *ActionRepository, re tablets := [](*topodatapb.Tablet){} for _, shard := range shardNames { - // Get tables for this shard. + // Get tablets for this shard. tabletAliases, err := ts.FindAllTabletAliasesInShard(ctx, keyspace, shard) if err != nil && !topo.IsErrType(err, topo.PartialResult) { return nil, err