-
Notifications
You must be signed in to change notification settings - Fork 341
/
snapshot.go
73 lines (61 loc) · 2.14 KB
/
snapshot.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
70
71
72
73
package hdfs
import (
hdfs "github.com/colinmarc/hdfs/v2/internal/protocol/hadoop_hdfs"
)
// AllowSnapshots marks a directory as available for snapshots.
// This is required to make a snapshot of a directory as snapshottable
// directories work as a whitelist.
//
// This requires superuser privileges.
func (c *Client) AllowSnapshots(dir string) error {
allowSnapshotReq := &hdfs.AllowSnapshotRequestProto{SnapshotRoot: &dir}
allowSnapshotRes := &hdfs.AllowSnapshotResponseProto{}
err := c.namenode.Execute("allowSnapshot", allowSnapshotReq, allowSnapshotRes)
if err != nil {
return interpretException(err)
}
return nil
}
// DisallowSnapshots marks a directory as unavailable for snapshots.
//
// This requires superuser privileges.
func (c *Client) DisallowSnapshots(dir string) error {
disallowSnapshotReq := &hdfs.DisallowSnapshotRequestProto{SnapshotRoot: &dir}
disallowSnapshotRes := &hdfs.DisallowSnapshotResponseProto{}
err := c.namenode.Execute("disallowSnapshot", disallowSnapshotReq, disallowSnapshotRes)
if err != nil {
return interpretException(err)
}
return nil
}
// CreateSnapshots creates a snapshot of a given directory and name, and
// returns the path containing the snapshot. Snapshot names must be unique.
//
// This requires superuser privileges.
func (c *Client) CreateSnapshot(dir, name string) (string, error) {
allowSnapshotReq := &hdfs.CreateSnapshotRequestProto{
SnapshotRoot: &dir,
SnapshotName: &name,
}
allowSnapshotRes := &hdfs.CreateSnapshotResponseProto{}
err := c.namenode.Execute("createSnapshot", allowSnapshotReq, allowSnapshotRes)
if err != nil {
return "", interpretException(err)
}
return allowSnapshotRes.GetSnapshotPath(), nil
}
// CreateSnapshots deletes a snapshot with a given directory and name.
//
// This requires superuser privileges.
func (c *Client) DeleteSnapshot(dir, name string) error {
allowSnapshotReq := &hdfs.DeleteSnapshotRequestProto{
SnapshotRoot: &dir,
SnapshotName: &name,
}
allowSnapshotRes := &hdfs.DeleteSnapshotResponseProto{}
err := c.namenode.Execute("deleteSnapshot", allowSnapshotReq, allowSnapshotRes)
if err != nil {
return interpretException(err)
}
return nil
}