-
Notifications
You must be signed in to change notification settings - Fork 111
/
put.go
38 lines (32 loc) · 778 Bytes
/
put.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
package rs
import (
"fmt"
"io"
"lib/objectstream"
)
type RSPutStream struct {
*encoder
}
func NewRSPutStream(dataServers []string, hash string, size int64) (*RSPutStream, error) {
if len(dataServers) != ALL_SHARDS {
return nil, fmt.Errorf("dataServers number mismatch")
}
perShard := (size + DATA_SHARDS - 1) / DATA_SHARDS
writers := make([]io.Writer, ALL_SHARDS)
var e error
for i := range writers {
writers[i], e = objectstream.NewTempPutStream(dataServers[i],
fmt.Sprintf("%s.%d", hash, i), perShard)
if e != nil {
return nil, e
}
}
enc := NewEncoder(writers)
return &RSPutStream{enc}, nil
}
func (s *RSPutStream) Commit(success bool) {
s.Flush()
for i := range s.writers {
s.writers[i].(*objectstream.TempPutStream).Commit(success)
}
}