Skip to content
This repository has been archived by the owner on Dec 8, 2021. It is now read-only.

checkpoint: fix empty map become nil after unmarshall #237

Merged
merged 3 commits into from Sep 6, 2019
Merged

Conversation

lance6716
Copy link
Contributor

What problem does this PR solve?

fix empty map become nil after marshall and unmarshall

What is changed and how it works?

manually init these map. Seems it's a bug of marshall function provided by gogoproto.

Check List

Tests

  • Unit test, add an unit test. If we didn't init these map after unmarshall this test won't pass(hope I didn't make it wrong)

Side effects

Related changes

  • Need to cherry-pick to the release branch

@lance6716 lance6716 added priority/normal Should Cherry-pick This PR should be cherry-picked back the previous release train status/PTAL This PR is ready for review. Add this label back after committing new changes type/bug-fix Bug fix labels Sep 6, 2019
@lance6716
Copy link
Contributor Author

/run-all-tests

PTAL @kennytm @GregoryIan

BTW patch branch for Tencent PCG is here and cherry-pick to 2.1 will be based on this pcg-debug

log.L().Error("checkpoint file is broken", zap.String("path", path), zap.Error(err2))
}
// FIXME: patch for empty map may need initialize manually, because currently
// FIXME: a map of zero size -> marshall -> unmarshall -> become nil, see checkpoint_test.go
Copy link
Collaborator

Choose a reason for hiding this comment

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

why using FIXME for these comments?

Copy link
Contributor Author

@lance6716 lance6716 Sep 6, 2019

Choose a reason for hiding this comment

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

I think it's an unexpected behaviour of gogo/protobuf's marshall and unmarshall. There's logic to recover a empty map(but didn't execute) in

if m.Engines == nil {
m.Engines = make(map[int32]*EngineCheckpointModel)

If gogo/protobuf fixed this bug, we won't bother to initiate. So I added a FIXME to remind to report bug and check if fixed from gogo/protobuf.

@IANTHEREAL
Copy link
Collaborator

Rest LGTM

Copy link
Collaborator

@kennytm kennytm left a comment

Choose a reason for hiding this comment

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

Rest LGTM

lightning/checkpoints/checkpoints_test.go Outdated Show resolved Hide resolved
@lance6716
Copy link
Contributor Author

/run-all-tests

@IANTHEREAL
Copy link
Collaborator

LGTM

@lance6716 lance6716 added status/LGT1 One reviewer already commented LGTM (LGTM1) and removed status/PTAL This PR is ready for review. Add this label back after committing new changes labels Sep 6, 2019
@kennytm kennytm added status/LGT2 Two reviewers already commented LGTM, ready for merge (LGTM2) and removed status/LGT1 One reviewer already commented LGTM (LGTM1) labels Sep 6, 2019
@kennytm kennytm merged commit aaac2b4 into master Sep 6, 2019
@kennytm kennytm deleted the fix-empty-map branch September 6, 2019 08:20
lance6716 added a commit that referenced this pull request Sep 6, 2019
* checkpoint: fix empty map become nil after unmarshall

* checkpoint: unify code style

* checkpoint: remove hard-coded path
lance6716 added a commit that referenced this pull request Sep 6, 2019
lance6716 added a commit that referenced this pull request Sep 6, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Should Cherry-pick This PR should be cherry-picked back the previous release train status/LGT2 Two reviewers already commented LGTM, ready for merge (LGTM2) type/bug-fix Bug fix
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants