Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix bugs to run demo #151

Merged
merged 3 commits into from
Feb 14, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions cmd/demoserver/kvdatamake.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ func (s *DataRWServer) ReadLines(req *pb.ReadLinesRequest, stream pb.DataRWServi
log.L().Info("receive the request for reading file ")
file, err := os.OpenFile(fileName, os.O_RDONLY, 0o666)
if err != nil {
log.L().Info("make sure the file exist ",
log.L().Error("make sure the file exist ",
zap.String("fileName ", fileName))
fmt.Printf("open file %v failed \n", fileName)
return err
Expand Down Expand Up @@ -261,7 +261,7 @@ func (s *DataRWServer) WriteLines(stream pb.DataRWService_WriteLinesServer) erro
} else {
index := strings.LastIndex(fileName, "/")
if index <= 1 {
log.L().Info("bad file name ",
log.L().Error("bad file name ",
zap.Int("index ", index))
return &ErrorInfo{info: " bad file name :" + fileName}
}
Expand All @@ -277,7 +277,7 @@ func (s *DataRWServer) WriteLines(stream pb.DataRWService_WriteLinesServer) erro
if err != nil {
return &ErrorInfo{info: "create the folder " + folder + " failed"}
}
log.L().Info("create the folder ",
log.L().Error("create the folder ",
zap.String("folder ", folder))
}
// create the file
Expand All @@ -299,12 +299,12 @@ func (s *DataRWServer) WriteLines(stream pb.DataRWService_WriteLinesServer) erro
err = writer.Flush()
}
if err != nil {
log.L().Info("write data failed ",
log.L().Error("write data failed ",
zap.String("error ", err.Error()))
}

} else if err == io.EOF {
fmt.Printf("receive the eof %v \n", res.Key)
log.L().Info("receive the eof")
s.mu.Lock()
for _, w := range s.fileWriterMap {
w.Flush()
Expand Down
34 changes: 16 additions & 18 deletions executor/cvsTask/cvstask.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,14 @@ func (task *cvsTask) InitImpl(ctx context.Context) error {
go func() {
err := task.Receive(ctx)
if err != nil {
log.L().Info("error happened when reading data from the upstream ", zap.Any("message", err.Error()))
log.L().Error("error happened when reading data from the upstream ", zap.Any("message", err.Error()))
task.status = lib.WorkerStatusError
}
}()
go func() {
err := task.Send(ctx)
if err != nil {
log.L().Info("error happened when writing data to the downstream ", zap.Any("message", err.Error()))
log.L().Error("error happened when writing data to the downstream ", zap.Any("message", err.Error()))
task.status = lib.WorkerStatusError
}
}()
Expand Down Expand Up @@ -128,28 +128,28 @@ func (task *cvsTask) CloseImpl(ctx context.Context) error {
func (task *cvsTask) Receive(ctx context.Context) error {
conn, err := grpc.Dial(task.srcHost, grpc.WithInsecure())
if err != nil {
log.L().Info("cann't connect with the source address ", zap.Any("message", task.srcHost))
log.L().Error("cann't connect with the source address ", zap.Any("message", task.srcHost))
return err
}
client := pb.NewDataRWServiceClient(conn)
defer conn.Close()
reader, err := client.ReadLines(ctx, &pb.ReadLinesRequest{FileName: task.srcDir, LineNo: task.index})
if err != nil {
log.L().Info("read data from file failed ", zap.Any("message", task.srcDir))
log.L().Error("read data from file failed ", zap.Any("message", task.srcDir))
return err
}
for {
reply, err := reader.Recv()
if err != nil {
log.L().Info("read data failed", zap.Any("error:", err.Error()))
log.L().Error("read data failed", zap.Error(err))
if !task.isEOF {
task.cancelFn()
}
return err
}
if reply.IsEof {
log.L().Info("Reach the end of the file ", zap.Any("fileName:", task.srcDir))
task.isEOF = true
close(task.buffer)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if the server crash in the syncing process, the status should be set error

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

break
}
strs := strings.Split(reply.Linestr, ",")
Expand All @@ -169,40 +169,38 @@ func (task *cvsTask) Receive(ctx context.Context) error {
func (task *cvsTask) Send(ctx context.Context) error {
conn, err := grpc.Dial(task.dstHost, grpc.WithInsecure())
if err != nil {
log.L().Info("cann't connect with the destination address ", zap.Any("message", task.dstHost))
log.L().Error("cann't connect with the destination address ", zap.Any("message", task.dstHost))
return err
}
client := pb.NewDataRWServiceClient(conn)
defer conn.Close()
writer, err := client.WriteLines(ctx)
if err != nil {
log.L().Info("call write data rpc failed ")
log.L().Error("call write data rpc failed", zap.Error(err))
task.status = lib.WorkerStatusError
task.cancelFn()
return err
}
for {
select {
case kv := <-task.buffer:
case kv, more := <-task.buffer:
if !more {
log.L().Info("Reach the end of the file ")
task.status = lib.WorkerStatusFinished
_, err = writer.CloseAndRecv()
return err
}
err := writer.Send(&pb.WriteLinesRequest{FileName: task.dstDir, Key: kv.firstStr, Value: kv.secondStr})
task.counter++
if err != nil {
log.L().Info("call write data rpc failed ")
log.L().Error("call write data rpc failed ", zap.Error(err))
task.status = lib.WorkerStatusError
task.cancelFn()
return err
}
case <-ctx.Done():
task.status = lib.WorkerStatusError
return nil
default:
if task.isEOF {
log.L().Info("Reach the end of the file ")
task.status = lib.WorkerStatusFinished
err = writer.CloseSend()
return err
}
time.Sleep(time.Second)

}
}
Expand Down
8 changes: 3 additions & 5 deletions jobmaster/cvsJob/cvsJobMaster.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (e *errorInfo) Error() string {
}

type JobMaster struct {
lib.BaseJobMaster
lib.BaseMaster
syncInfo *Config
syncFilesInfo map[lib.WorkerID]*workerInfo
counter int64
Expand All @@ -61,19 +61,17 @@ func NewCVSJobMaster(ctx *dcontext.Context, workerID lib.WorkerID, masterID lib.
jm.syncFilesInfo = make(map[lib.WorkerID]*workerInfo)
deps := ctx.Dependencies

base := lib.NewBaseJobMaster(
base := lib.NewBaseMaster(
ctx,
jm,
jm,
masterID,
workerID,
deps.MessageHandlerManager,
deps.MessageRouter,
deps.MetaKVClient,
deps.ExecutorClientManager,
deps.ServerMasterClient,
)
jm.BaseJobMaster = base
jm.BaseMaster = base
log.L().Info("new cvs jobmaster ", zap.Any("id :", jm.workerID))
return jm
}
Expand Down