Skip to content

Use pipelines to read group state data, improved error handling - #896

Merged
dimpar merged 5 commits into
masterfrom
read-from-channel
Jul 1, 2019
Merged

Use pipelines to read group state data, improved error handling#896
dimpar merged 5 commits into
masterfrom
read-from-channel

Conversation

@pdyraga

@pdyraga pdyraga commented Jun 27, 2019

Copy link
Copy Markdown
Member

Closes: #657

Here we solve two problems:

  1. Potential memory issues related to loading all groups data into the memory at once

  2. Not enough context about failed data read operation and failing the entire operation because of one problematic file

Previously, we were loading all group data bytes into the memory and iterating over those data to create Memberships and store them in group registry. In case of any error related to reading storage directory or decrypting data, we were failing entire operation without providing enough context about which file caused problems.

We decided to refactor group data loading code into go pipelines and refine the information sent through the channels so that we can print error with precise information about the file (group membership) which could not be loaded.

See: https://blog.golang.org/pipelines

Proof

File corrupted:

➜  keep-core git:(read-from-channel) ✗ go build . && KEEP_ETHEREUM_PASSWORD="password" ./keep-core --config config.local.1.toml start
------------------------------------------------------------------------------------------------
| Node: BOOTSTRAP node                                                                         |
| Port: 0                                                                                      |
| IPs : /ip4/127.0.0.1/tcp/3919/ipfs/16Uiu2HAmPTB3EVq7PKCqBDH5qRBNxdddiodxMJcvMciZfLoUkac9     |
|       /ip6/::1/tcp/3919/ipfs/16Uiu2HAmPTB3EVq7PKCqBDH5qRBNxdddiodxMJcvMciZfLoUkac9           |
|       /ip4/192.168.1.103/tcp/3919/ipfs/16Uiu2HAmPTB3EVq7PKCqBDH5qRBNxdddiodxMJcvMciZfLoUkac9 |
------------------------------------------------------------------------------------------------
Could not load membership from disk: [could not unmarshal membership from file [membership_5] in directory [282b0f9acd8433e201a4b1879b2925765f0f334c5cb1b5c60d6644e165f3a56204e1274f40847c55c3e1ae86e0d072469604d6d6383ac92fee9db5b70a4a4f63]: [symmetric key decryption failed]]
Group [282b0f9acd8433e201a4b1879b2925765f0f334c5cb1b5c60d6644e165f3a56204e1274f40847c55c3e1ae86e0d072469604d6d6383ac92fee9db5b70a4a4f63] was loaded with member IDs [3]
Group [2ce42e92d22654b0f9b4a68156849f1dc52240c267f5f54de717e4acad37ac4e1524f09e311a05e5b48bbf3affe9b9d92ce8112a229b5d26da7f64ffae5e2e57] was loaded with member IDs [1, 4]

All files correct:

➜  keep-core git:(read-from-channel) ✗ go build . && KEEP_ETHEREUM_PASSWORD="password" ./keep-core --config config.local.1.toml start------------------------------------------------------------------------------------------------
| Node: BOOTSTRAP node                                                                         |
| Port: 0                                                                                      |
| IPs : /ip4/127.0.0.1/tcp/3919/ipfs/16Uiu2HAmPTB3EVq7PKCqBDH5qRBNxdddiodxMJcvMciZfLoUkac9     |
|       /ip6/::1/tcp/3919/ipfs/16Uiu2HAmPTB3EVq7PKCqBDH5qRBNxdddiodxMJcvMciZfLoUkac9           |
|       /ip4/192.168.1.103/tcp/3919/ipfs/16Uiu2HAmPTB3EVq7PKCqBDH5qRBNxdddiodxMJcvMciZfLoUkac9 |
------------------------------------------------------------------------------------------------
Group [2ce42e92d22654b0f9b4a68156849f1dc52240c267f5f54de717e4acad37ac4e1524f09e311a05e5b48bbf3affe9b9d92ce8112a229b5d26da7f64ffae5e2e57] was loaded with member IDs [1, 4]
Group [282b0f9acd8433e201a4b1879b2925765f0f334c5cb1b5c60d6644e165f3a56204e1274f40847c55c3e1ae86e0d072469604d6d6383ac92fee9db5b70a4a4f63] was loaded with member IDs [3, 5]

pdyraga added 5 commits June 27, 2019 11:44
Here we solve two problems:

1. Potential memory issues related to loading all groups data into the
memory at once

2. Not enough context about failed data read operation and failing
entire operation because one problematic file

Previously, we were loading all group data bytes into the memory and
iterating over those data to create Memberships and store them in group
registry. In case of any error related to reading storage directory or
decrypting data, we were failing entire operation without providing
enough context about which file caused problems.

We decided to refactor group data loading code into go pipelines and
refine the information sent through the channels so that we can print
error with a precise information about the file (group membership)
which could not be loaded.
We no longer return an error from LoadExistingGroup. In case of any
problematic situation, we log the error to STDERR.
We start this function as `go groupRegistry.UnregisterStaleGroups()` in
beacon.go and we ignore errors there. There is really nothing else we
can do than logging an error in case something wrong happened in
`UnregisterStaleGroups`. To avoid losing the errors, we now log them in
`UnregisterStaleGroups` and this function no longer return any error.
Tests have been refactored to avoid deadlocks - channels are not
buffered so we need to read from them asynchronously to do not block the
test on ReadAll execution.
File name should go as first, then directory name and callback.
@pdyraga
pdyraga requested review from dimpar and ngrinkevich June 27, 2019 10:35
@dimpar

dimpar commented Jun 30, 2019

Copy link
Copy Markdown
Contributor

Testing looks good. I manually corrupted 2 files and they were not loaded.

-------------------------------------------------------------------------------------------------------------------------
| Node: BOOTSTRAP node                                                                                                  |
| Port: 0                                                                                                               |
| IPs : /ip4/127.0.0.1/tcp/3919/ipfs/16Uiu2HAmSNR3Yy6LcyGpWZER6RQQWpEo2rJrdpcA1QzXASgJVExa                              |
|       /ip6/::1/tcp/3919/ipfs/16Uiu2HAmSNR3Yy6LcyGpWZER6RQQWpEo2rJrdpcA1QzXASgJVExa                                    |
|       /ip4/192.168.1.28/tcp/3919/ipfs/16Uiu2HAmSNR3Yy6LcyGpWZER6RQQWpEo2rJrdpcA1QzXASgJVExa                           |
|       /ip6/2a01:114f:9a5:9100:10bf:d6c3:bf65:44d7/tcp/3919/ipfs/16Uiu2HAmSNR3Yy6LcyGpWZER6RQQWpEo2rJrdpcA1QzXASgJVExa |
|       /ip6/2a01:114f:9a5:9100:fdf0:7081:17b0:85be/tcp/3919/ipfs/16Uiu2HAmSNR3Yy6LcyGpWZER6RQQWpEo2rJrdpcA1QzXASgJVExa |
-------------------------------------------------------------------------------------------------------------------------
Could not load membership from disk: [could not unmarshal membership from file [membership_3] in directory [29bb779843e2a5cee788f412e33c8569371156f8a3c2572ffc247b335683b3530ce7f942717eb1d1ec4848a85719af3d7bfcc3f63e3323c4af17fcc39a6c4ed4]: [symmetric key decryption failed]]
Could not load membership from disk: [could not unmarshal membership from file [membership_5] in directory [29bb779843e2a5cee788f412e33c8569371156f8a3c2572ffc247b335683b3530ce7f942717eb1d1ec4848a85719af3d7bfcc3f63e3323c4af17fcc39a6c4ed4]: [symmetric key decryption failed]]
Group [29bb779843e2a5cee788f412e33c8569371156f8a3c2572ffc247b335683b3530ce7f942717eb1d1ec4848a85719af3d7bfcc3f63e3323c4af17fcc39a6c4ed4] was loaded with member IDs [1, 2, 4]

@dimpar dimpar left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks very nice! I have no comments.

@dimpar
dimpar merged commit f5d3bd7 into master Jul 1, 2019
@mhluongo
mhluongo deleted the read-from-channel branch June 10, 2020 17:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Keep client group membership state management

2 participants