Skip to content
This repository was archived by the owner on Feb 18, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 3 additions & 3 deletions go/app/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -1353,15 +1353,15 @@ func Cli(command string, strict bool, instance string, destination string, owner
}
case registerCliCommand("forget", "Instance management", `Forget about an instance's existence`):
{
instanceKey, _ = inst.FigureInstanceKey(instanceKey, thisInstanceKey)
if rawInstanceKey == nil {
log.Fatal("Cannot deduce instance:", instance)
}
err := inst.ForgetInstance(rawInstanceKey)
instanceKey, _ = inst.FigureInstanceKey(rawInstanceKey, nil)
err := inst.ForgetInstance(instanceKey)
if err != nil {
log.Fatale(err)
}
fmt.Println(rawInstanceKey.DisplayString())
fmt.Println(instanceKey.DisplayString())
}
case registerCliCommand("begin-maintenance", "Instance management", `Request a maintenance lock on an instance`):
{
Expand Down
38 changes: 31 additions & 7 deletions go/http/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,18 +124,35 @@ var API HttpAPI = HttpAPI{}
var discoveryMetrics = collection.CreateOrReturnCollection("DISCOVERY_METRICS")
var queryMetrics = collection.CreateOrReturnCollection("BACKEND_WRITES")

func (this *HttpAPI) getInstanceKey(host string, port string) (inst.InstanceKey, error) {
instanceKey, err := inst.NewResolveInstanceKeyStrings(host, port)
func (this *HttpAPI) getInstanceKeyInternal(host string, port string, resolve bool) (inst.InstanceKey, error) {
var instanceKey *inst.InstanceKey
var err error
if resolve {
instanceKey, err = inst.NewResolveInstanceKeyStrings(host, port)
} else {
instanceKey, err = inst.NewRawInstanceKeyStrings(host, port)
}
if err != nil {
return emptyInstanceKey, err
}
instanceKey, err = inst.FigureInstanceKey(instanceKey, nil)
if err != nil {
return emptyInstanceKey, err
}
if instanceKey == nil {
return emptyInstanceKey, fmt.Errorf("Unexpected nil instanceKey in getInstanceKeyInternal(%+v, %+v, %+v)", host, port, resolve)
}
return *instanceKey, nil
}

func (this *HttpAPI) getInstanceKey(host string, port string) (inst.InstanceKey, error) {
return this.getInstanceKeyInternal(host, port, true)
}

func (this *HttpAPI) getNoResolveInstanceKey(host string, port string) (inst.InstanceKey, error) {
return this.getInstanceKeyInternal(host, port, false)
}

func getTag(params martini.Params, req *http.Request) (tag *inst.Tag, err error) {
tagString := req.URL.Query().Get("tag")
if tagString != "" {
Expand Down Expand Up @@ -259,15 +276,22 @@ func (this *HttpAPI) Forget(params martini.Params, r render.Render, req *http.Re
Respond(r, &APIResponse{Code: ERROR, Message: "Unauthorized"})
return
}
// We ignore errors: we're looking to do a destructive operation anyhow.
rawInstanceKey, _ := inst.NewRawInstanceKeyStrings(params["host"], params["port"])
instanceKey, err := this.getNoResolveInstanceKey(params["host"], params["port"])
if err != nil {
Respond(r, &APIResponse{Code: ERROR, Message: err.Error()})
return
}

if orcraft.IsRaftEnabled() {
orcraft.PublishCommand("forget", rawInstanceKey)
_, err = orcraft.PublishCommand("forget", instanceKey)
} else {
inst.ForgetInstance(rawInstanceKey)
err = inst.ForgetInstance(&instanceKey)
}
if err != nil {
Respond(r, &APIResponse{Code: ERROR, Message: err.Error()})
return
}
Respond(r, &APIResponse{Code: OK, Message: fmt.Sprintf("Instance forgotten: %+v", *rawInstanceKey)})
Respond(r, &APIResponse{Code: OK, Message: fmt.Sprintf("Instance forgotten: %+v", instanceKey), Details: instanceKey})
}

// ForgetCluster forgets all instacnes of a cluster
Expand Down
17 changes: 15 additions & 2 deletions go/inst/instance_dao.go
Original file line number Diff line number Diff line change
Expand Up @@ -2545,17 +2545,30 @@ func InstanceIsForgotten(instanceKey *InstanceKey) bool {
// ForgetInstance removes an instance entry from the orchestrator backed database.
// It may be auto-rediscovered through topology or requested for discovery by multiple means.
func ForgetInstance(instanceKey *InstanceKey) error {
if instanceKey == nil {
return log.Errorf("ForgetInstance(): nil instanceKey")
}
forgetInstanceKeys.Set(instanceKey.StringCode(), true, cache.DefaultExpiration)
_, err := db.ExecOrchestrator(`
sqlResult, err := db.ExecOrchestrator(`
delete
from database_instance
where
hostname = ? and port = ?`,
instanceKey.Hostname,
instanceKey.Port,
)
if err != nil {
return log.Errore(err)
}
rows, err := sqlResult.RowsAffected()
if err != nil {
return log.Errore(err)
}
if rows == 0 {
return log.Errorf("ForgetInstance(): instance %+v not found", *instanceKey)
}
AuditOperation("forget", instanceKey, "")
return err
return nil
}

// ForgetInstance removes an instance entry from the orchestrator backed database.
Expand Down