forked from colinmarc/hdfs
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathepoch.go
More file actions
37 lines (28 loc) · 722 Bytes
/
epoch.go
File metadata and controls
37 lines (28 loc) · 722 Bytes
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
package hdfs
import (
"time"
hdfs "github.com/colinmarc/hdfs/v2/internal/protocol/hadoop_hdfs"
"github.com/colinmarc/hdfs/v2/internal/rpc"
)
// Get epoch from the namenode
func (c *Client) getNNEpochMS() (int64, error) {
req := &hdfs.GetEpochMSRequestProto{}
resp := &hdfs.GetEpochMSResponseProto{}
err := c.leaderNamenode.Execute("getNNEpochMS", req, resp)
if err != nil {
return 0, interpretException(err)
}
return resp.GetEpoch(), nil
}
func (c *Client) setEpoch() error {
start := time.Now()
epoch, err := c.getNNEpochMS()
endTime := time.Now()
diff := time.Since(start).Milliseconds() / 2
if err != nil {
return err
}
epoch = epoch + diff
rpc.SetEpoch(endTime, epoch+diff)
return nil
}