forked from colinmarc/hdfs
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathreplication.go
More file actions
38 lines (31 loc) · 1.01 KB
/
replication.go
File metadata and controls
38 lines (31 loc) · 1.01 KB
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
package hdfs
import (
"errors"
"os"
hdfs "github.com/colinmarc/hdfs/v2/internal/protocol/hadoop_hdfs"
"google.golang.org/protobuf/proto"
)
// Sets replication factor for a file
func (c *Client) SetReplication(name string, replication int16) (bool, error) {
return setReplication(c, name, replication)
}
func setReplication(c *Client, name string, replication int16) (bool, error) {
_, err := c.getFileInfo(name)
if err != nil {
return false, &os.PathError{Op: "remove", Path: name, Err: err}
}
req := &hdfs.SetReplicationRequestProto{
Src: proto.String(name),
Replication: proto.Uint32(uint32(replication)),
}
resp := &hdfs.SetReplicationResponseProto{}
err = c.leaderNamenode.Execute("setReplication", req, resp)
if err != nil {
return false, &os.PathError{Op: "setReplication", Path: name,
Err: interpretException(err)}
} else if resp.Result == nil {
return false, &os.PathError{Op: "setReplication", Path: name,
Err: errors.New("unexpected empty response")}
}
return *resp.Result, nil
}