Skip to content

Commit

Permalink
loss fileID cause write failed
Browse files Browse the repository at this point in the history
  • Loading branch information
982945902 authored Aug 29, 2022
1 parent 545c98f commit da8cb33
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions file_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type FileWriter struct {
name string
replication int
blockSize int64
fileId *uint64

blockWriter *transfer.BlockWriter
deadline time.Time
Expand Down Expand Up @@ -82,6 +83,7 @@ func (c *Client) CreateFile(name string, replication int, blockSize int64, perm
name: name,
replication: replication,
blockSize: blockSize,
fileId: createResp.Fs.FileId,
}, nil
}

Expand Down Expand Up @@ -111,6 +113,7 @@ func (c *Client) Append(name string) (*FileWriter, error) {
name: name,
replication: int(appendResp.Stat.GetBlockReplication()),
blockSize: int64(appendResp.Stat.GetBlocksize()),
fileId: appendResp.Stat.FileId,
}

// This returns nil if there are no blocks (it's an empty file) or if the
Expand Down Expand Up @@ -233,23 +236,15 @@ func (f *FileWriter) Close() error {
}
}

getFileInfoReq := &hdfs.GetFileInfoRequestProto{Src: proto.String(f.name)}
getFileInfoResp := &hdfs.GetFileInfoResponseProto{}

err := f.client.namenode.Execute("getFileInfo", getFileInfoReq, getFileInfoResp)
if err != nil {
return &os.PathError{"getFileInfo", f.name, err}
}

completeReq := &hdfs.CompleteRequestProto{
Src: proto.String(f.name),
ClientName: proto.String(f.client.namenode.ClientName),
Last: lastBlock,
FileId: getFileInfoResp.Fs.FileId,
FileId: f.fileId,
}
completeResp := &hdfs.CompleteResponseProto{}

err = f.client.namenode.Execute("complete", completeReq, completeResp)
err := f.client.namenode.Execute("complete", completeReq, completeResp)
if err != nil {
return &os.PathError{"create", f.name, err}
} else if completeResp.GetResult() == false {
Expand All @@ -276,6 +271,7 @@ func (f *FileWriter) startNewBlock() error {
Src: proto.String(f.name),
ClientName: proto.String(f.client.namenode.ClientName),
Previous: previous,
FileId: f.fileId,
}
addBlockResp := &hdfs.AddBlockResponseProto{}

Expand Down

0 comments on commit da8cb33

Please sign in to comment.