Skip to content

Commit

Permalink
Merge #60744 #60952
Browse files Browse the repository at this point in the history
60744: sql: drop default value when its dependent sequence is dropped r=the-ericwang35 a=the-ericwang35

Fixes #51889 and #20965.

Previously, we did not support `DROP SEQUENCE ... CASCADE`,
and we simply disallowed dropping sequences that have usages by 
tables when a user tries to drop a sequence.

However,  we did not make this check when doing 
`DROP DATABASE/SCHEMA ... CASCADE`. As a result,
if a sequence is used by a table in a different database/schema,
we end up dropping a sequence that the table still relies on,
resulting in a corrupted default expression.

This patch addresses this issue by implementing 
`DROP SCHEMA ... CASCADE`, which solves the above issue.
When we drop anything that contains/owns a sequence with
`CASCADE`, we drop those sequences as if 
`DROP SCHEMA ... CASCADE` was called on them, which
prevents the `DEFAULT` expressions from being corrupted, 
and also allows users to use `DROP SEQUENCE ... CASCADE.

`DROP SEQUENCE ... CASCADE` behaves as in Postgres, 
wherein any default expressions that rely on the dropped 
sequences are also dropped.

Release note (bug fix): Fixed a bug which could result in corrupted descriptors when dropping a database which contains a sequence that was referenced from another database.

Release note (bug fix): Fixed a bug where DROP SEQUENCE CASCADE would not properly remove references to itself from table default expressions.

Release note (sql change): Added support for dropping a table which owns a sequence. 

Release justification: low risk bug fix for existing functionality

60952: server: Migrate nodes, {hot-,}ranges, health endpoints to v2 API r=knz a=itsbilal

This change adds API v2 compatible versions of the node list, range info
per node, ranges info across nodes, hot ranges, and health endpoints.
These endpoints all support API v2 header-based authentication,
pagination (if applicable), and only return relevant information
in the response payloads.

One part of #55947.

Release note (api change): Add these new HTTP API endpoints:
 - `/api/v2/nodes/`: Lists all nodes in the cluster
 - `/api/v2/nodes/<node_id>/ranges`: Lists all ranges on the specified node
 - `/api/v2/ranges/hot/`: Lists hot ranges in the cluster
 - `/api/v2/ranges/<range_id>/`: Describes range in more detail
 - `/api/v2/health/`: Returns an HTTP 200 response if node is healthy.

Release justification: Adds more HTTP API endpoints in parallel
 that do not touch existing code.

Co-authored-by: Eric Wang <[email protected]>
Co-authored-by: Bilal Akhtar <[email protected]>
  • Loading branch information
3 people committed Feb 26, 2021
3 parents be0383e + c02dd6f + 7c55798 commit de72eae
Show file tree
Hide file tree
Showing 17 changed files with 1,201 additions and 138 deletions.
9 changes: 6 additions & 3 deletions pkg/server/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ go_library(
name = "server",
srcs = [
"admin.go",
"api.go",
"api_auth.go",
"api_error.go",
"api_v2.go",
"api_v2_auth.go",
"api_v2_error.go",
"api_v2_ranges.go",
"authentication.go",
"auto_tls_init.go",
"auto_upgrade.go",
Expand Down Expand Up @@ -236,6 +237,8 @@ go_test(
srcs = [
"admin_cluster_test.go",
"admin_test.go",
"api_v2_ranges_test.go",
"api_v2_test.go",
"authentication_test.go",
"auto_tls_init_test.go",
"config_test.go",
Expand Down
37 changes: 36 additions & 1 deletion pkg/server/api.go → pkg/server/api_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"encoding/json"
"fmt"
"net/http"
"strconv"

"github.com/cockroachdb/cockroach/pkg/server/serverpb"
"github.com/cockroachdb/cockroach/pkg/server/telemetry"
Expand Down Expand Up @@ -102,6 +103,13 @@ func (a *apiV2Server) registerRoutes(innerMux *mux.Router, authMux http.Handler)

// Directly register other endpoints in the api server.
{"sessions/", a.listSessions, true /* requiresAuth */, adminRole, noOption},
{"nodes/", a.listNodes, true, adminRole, noOption},
// Any endpoint returning range information requires an admin user. This is because range start/end keys
// are sensitive info.
{"nodes/{node_id}/ranges/", a.listNodeRanges, true, adminRole, noOption},
{"ranges/hot/", a.listHotRanges, true, adminRole, noOption},
{"ranges/{range_id:[0-9]+}/", a.listRange, true, adminRole, noOption},
{"health/", a.health, false, regularRole, noOption},
}

// For all routes requiring authentication, have the outer mux (a.mux)
Expand Down Expand Up @@ -148,7 +156,7 @@ func (c *callCountDecorator) ServeHTTP(w http.ResponseWriter, req *http.Request)
type listSessionsResponse struct {
serverpb.ListSessionsResponse

Next string `json:"next"`
Next string `json:"next,omitempty"`
}

func (a *apiV2Server) listSessions(w http.ResponseWriter, r *http.Request) {
Expand All @@ -174,3 +182,30 @@ func (a *apiV2Server) listSessions(w http.ResponseWriter, r *http.Request) {
response.ListSessionsResponse = *responseProto
writeJSONResponse(ctx, w, http.StatusOK, response)
}

func (a *apiV2Server) health(w http.ResponseWriter, r *http.Request) {
ready := false
readyStr := r.URL.Query().Get("ready")
if len(readyStr) > 0 {
var err error
ready, err = strconv.ParseBool(readyStr)
if err != nil {
http.Error(w, "invalid ready value", http.StatusBadRequest)
return
}
}
ctx := r.Context()
resp := &serverpb.HealthResponse{}
// If Ready is not set, the client doesn't want to know whether this node is
// ready to receive client traffic.
if !ready {
writeJSONResponse(ctx, w, 200, resp)
return
}

if err := a.admin.checkReadinessForHealthCheck(ctx); err != nil {
apiV2InternalError(ctx, err, w)
return
}
writeJSONResponse(ctx, w, 200, resp)
}
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit de72eae

Please sign in to comment.