-
Notifications
You must be signed in to change notification settings - Fork 30
/
store_grpc_server_delete_keyspace.go
69 lines (58 loc) · 1.66 KB
/
store_grpc_server_delete_keyspace.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package store
import (
"fmt"
"github.com/chrislusf/glog"
"github.com/chrislusf/vasto/pb"
"golang.org/x/net/context"
"os"
)
// DeleteKeyspace
// 1. if the shard is already created, do nothing
func (ss *storeServer) DeleteKeyspace(ctx context.Context, request *pb.DeleteKeyspaceRequest) (*pb.DeleteKeyspaceResponse, error) {
glog.V(1).Infof("delete keyspace %v", request)
err := ss.deleteShards(request.Keyspace, true)
if err != nil {
glog.Errorf("delete keyspace %s: %v", request.Keyspace, err)
return &pb.DeleteKeyspaceResponse{
Error: err.Error(),
}, nil
}
return &pb.DeleteKeyspaceResponse{
Error: "",
}, nil
}
func (ss *storeServer) deleteShards(keyspace string, shouldTellMaster bool) (err error) {
// notify master of the deleted shards
if shouldTellMaster {
localShards, found := ss.getServerStatusInCluster(keyspace)
if !found {
return nil
}
for _, shardInfo := range localShards.ShardMap {
ss.sendShardInfoToMaster(shardInfo, pb.ShardInfo_DELETED)
}
}
// physically delete the shards
shards, found := ss.keyspaceShards.getShards(keyspace)
if !found {
return nil
}
for _, shard := range shards {
ss.shutdownShard(shard)
}
// remove all meta info and in-memory objects
dir := fmt.Sprintf("%s/%s", *ss.option.Dir, keyspace)
os.RemoveAll(dir)
ss.keyspaceShards.deleteKeyspace(keyspace)
ss.deleteServerStatusInCluster(keyspace)
ss.clusterListener.RemoveKeyspace(keyspace)
return nil
}
func (ss *storeServer) shutdownShard(shard *shard) {
ss.UnregisterPeriodicTask(shard)
shard.clusterListener.UnregisterShardEventProcessor(shard)
shard.shutdownNode()
shard.db.Close()
shard.db.Destroy()
ss.keyspaceShards.removeShard(shard)
}