Skip to content

Commit

Permalink
pretty formatting, from review
Browse files Browse the repository at this point in the history
  • Loading branch information
juagargi committed Sep 4, 2020
1 parent 1fb61e5 commit 04ad898
Showing 1 changed file with 27 additions and 26 deletions.
53 changes: 27 additions & 26 deletions go/cs/reservationstore/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ func (s *Store) AdmitSegmentReservation(ctx context.Context, req *segment.SetupR
return nil, serrors.New("inconsistent number of hops",
"len_alloctrail", len(req.AllocTrail), "hf_count", req.IndexOfCurrentHop())
}

response, err := s.prepareFailureSegmentResp(&req.Request)
if err != nil {
return nil, serrors.WrapStr("cannot construct response", err, "id", req.ID)
Expand All @@ -64,6 +65,7 @@ func (s *Store) AdmitSegmentReservation(ctx context.Context, req *segment.SetupR
Response: *response,
FailedSetup: req,
}

tx, err := s.db.BeginTransaction(ctx, nil)
if err != nil {
return failedResponse, serrors.WrapStr("cannot create transaction", err,
Expand Down Expand Up @@ -118,25 +120,24 @@ func (s *Store) AdmitSegmentReservation(ctx context.Context, req *segment.SetupR
}
// admitted; the request contains already the value inside the "allocation beads" of the rsv
index.AllocBW = req.AllocTrail[len(req.AllocTrail)-1].AllocBW

if err = tx.PersistSegmentRsv(ctx, rsv); err != nil {
return failedResponse, serrors.WrapStr("cannot persist segment reservation", err,
"id", req.ID)
}
if err := tx.Commit(); err != nil {
return failedResponse, serrors.WrapStr("cannot commit transaction", err, "id", req.ID)
}
var msg base.MessageWithPath

if req.IsLastAS() {
// TODO(juagargi) update token here
msg = &segment.ResponseSetupSuccess{
return &segment.ResponseSetupSuccess{
Response: *morphSegmentResponseToSuccess(response),
Token: *index.Token,
}
} else {
msg = req
}, nil
}
// TODO(juagargi) refactor function
return msg, nil
return req, nil
}

// ConfirmSegmentReservation changes the state of an index from temporary to confirmed.
Expand Down Expand Up @@ -194,6 +195,7 @@ func (s *Store) CleanupSegmentReservation(ctx context.Context, req *segment.Clea
if err := s.validateAuthenticators(&req.RequestMetadata); err != nil {
return nil, serrors.WrapStr("error validating request", err, "id", req.ID)
}

response, err := s.prepareFailureSegmentResp(&req.Request)
if err != nil {
return nil, serrors.WrapStr("cannot construct response", err, "id", req.ID)
Expand All @@ -202,6 +204,7 @@ func (s *Store) CleanupSegmentReservation(ctx context.Context, req *segment.Clea
Response: *response,
ErrorCode: 1,
}

tx, err := s.db.BeginTransaction(ctx, nil)
if err != nil {
return failedResponse, serrors.WrapStr("cannot create transaction", err, "id", req.ID)
Expand All @@ -225,16 +228,13 @@ func (s *Store) CleanupSegmentReservation(ctx context.Context, req *segment.Clea
return failedResponse, serrors.WrapStr("cannot commit transaction", err,
"id", req.ID)
}
var msg base.MessageWithPath

if req.IsLastAS() {
msg = &segment.ResponseCleanupSuccess{
return &segment.ResponseCleanupSuccess{
Response: *morphSegmentResponseToSuccess(response),
}
} else {
msg = req
}, nil
}

return msg, nil
return req, nil
}

// TearDownSegmentReservation removes a whole segment reservation.
Expand All @@ -244,6 +244,7 @@ func (s *Store) TearDownSegmentReservation(ctx context.Context, req *segment.Tea
if err := s.validateAuthenticators(&req.RequestMetadata); err != nil {
return nil, serrors.WrapStr("error validating request", err, "id", req.ID)
}

response, err := s.prepareFailureSegmentResp(&req.Request)
if err != nil {
return nil, serrors.WrapStr("cannot construct response", err, "id", req.ID)
Expand All @@ -252,6 +253,7 @@ func (s *Store) TearDownSegmentReservation(ctx context.Context, req *segment.Tea
Response: *response,
ErrorCode: 1,
}

tx, err := s.db.BeginTransaction(ctx, nil)
if err != nil {
return failedResponse, serrors.WrapStr("cannot create transaction", err, "id", req.ID)
Expand All @@ -266,16 +268,13 @@ func (s *Store) TearDownSegmentReservation(ctx context.Context, req *segment.Tea
return failedResponse, serrors.WrapStr("cannot commit transaction", err,
"id", req.ID)
}
var msg base.MessageWithPath

if req.IsLastAS() {
msg = &segment.ResponseTeardownSuccess{
return &segment.ResponseTeardownSuccess{
Response: *morphSegmentResponseToSuccess(response),
}
} else {
msg = req
}, nil
}

return msg, nil
return req, nil
}

// AdmitE2EReservation will atempt to admit an e2e reservation.
Expand All @@ -292,6 +291,7 @@ func (s *Store) CleanupE2EReservation(ctx context.Context, req *e2e.CleanupReq)
if err := s.validateAuthenticators(&req.RequestMetadata); err != nil {
return nil, serrors.WrapStr("error validating request", err, "id", req.ID)
}

response, err := s.prepareFailureE2EResp(&req.Request)
if err != nil {
return nil, serrors.WrapStr("cannot construct response", err, "id", req.ID)
Expand All @@ -300,6 +300,7 @@ func (s *Store) CleanupE2EReservation(ctx context.Context, req *e2e.CleanupReq)
Response: *response,
ErrorCode: 1,
}

tx, err := s.db.BeginTransaction(ctx, nil)
if err != nil {
return failedResponse, serrors.WrapStr("cannot create transaction", err, "id", req.ID)
Expand All @@ -323,16 +324,14 @@ func (s *Store) CleanupE2EReservation(ctx context.Context, req *e2e.CleanupReq)
return failedResponse, serrors.WrapStr("cannot commit transaction", err,
"id", req.ID)
}
var msg base.MessageWithPath

if req.IsLastAS() {
msg = &e2e.ResponseCleanupSuccess{
return &e2e.ResponseCleanupSuccess{
Response: *morphE2EResponseToSuccess(response),
}
} else {
msg = req
}, nil
}

return msg, nil
return req, nil
}

// DeleteExpiredIndices will just call the DB's method to delete the expired indices.
Expand All @@ -354,6 +353,7 @@ func (s *Store) prepareFailureSegmentResp(req *segment.Request) (*segment.Respon
if err := revPath.Reverse(); err != nil {
return nil, serrors.WrapStr("cannot reverse path for response", err)
}

response, err := segment.NewResponse(time.Now(), &req.ID, req.Index, revPath,
false, uint8(req.IndexOfCurrentHop()))
if err != nil {
Expand All @@ -369,6 +369,7 @@ func (s *Store) prepareFailureE2EResp(req *e2e.Request) (*e2e.Response, error) {
if err := revPath.Reverse(); err != nil {
return nil, serrors.WrapStr("cannot reverse path for response", err)
}

response, err := e2e.NewResponse(time.Now(), &req.ID, req.Index, revPath,
false, uint8(req.IndexOfCurrentHop()))
if err != nil {
Expand Down

0 comments on commit 04ad898

Please sign in to comment.