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

Dynamo use gloabal worker #624

Merged
merged 16 commits into from Aug 19, 2020
Merged

Conversation

joowon-byun
Copy link
Contributor

@joowon-byun joowon-byun commented Aug 14, 2020

Proposed changes

  • non-single DynamoDB can be created
    • If you set table name as dynamo-table, tables such as dynamo-table-body, dynamo-table-header, dynamo-table-statetrie, and so on will be created.
  • All DynamoDB tables will share a worker pool.
  • Sharded DB is not enabled for dynamoDB.

Types of changes

Please put an x in the boxes related to your change.

  • Bugfix
  • New feature or enhancement
  • Others

Checklist

Put an x in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code.

  • I have read the CONTRIBUTING GUIDELINES doc
  • I have signed the CLA
  • Lint and unit tests pass locally with my changes ($ make test)
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)
  • Any dependent changes have been merged and published in downstream modules

Related issues

Further comments

Co-authored-by: Melvin Junhee Woo <melvin.woo@groundx.xyz>
ehnuje
ehnuje previously approved these changes Aug 14, 2020
@CLAassistant
Copy link

CLAassistant commented Aug 18, 2020

CLA assistant check
All committers have signed the CLA.

aidan-kwon
aidan-kwon previously approved these changes Aug 18, 2020
Copy link
Member

@aidan-kwon aidan-kwon left a comment

Choose a reason for hiding this comment

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

LGTM

aidan-kwon
aidan-kwon previously approved these changes Aug 18, 2020
@@ -474,7 +487,7 @@ func (batch *dynamoBatch) Put(key, val []byte) error {

if len(batch.batchItems) == dynamoBatchSize {
batch.wg.Add(1)
batch.db.writeCh <- &batchWriteWorkerInput{batch.batchItems, batch.wg}
dynamoWriteCh <- &batchWriteWorkerInput{batch.tableName, batch.batchItems, batch.wg}
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there any possibility of panic if Close is called while processing Put operation?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've just tested.
A panic will not occur even though Close() is called on non-empty channel. (call Put() -> Close()) It will close after all of the items are processed.
However, a panic will occur when put is called in a closed channel (call Close() -> Put()).

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes. To avoid the second case, we need to use switch & case. Do you have any other alternatives?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If we use the original code, not all of the items in the channel will be processed. There might be some items we expect to be writen but actually no. Actually, in the original code, it will wait inifinitively in Write() because the workers will not process the input and wg.Done() is not called.
Is there other ways to handle both cases?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we don't need to consider the 2nd case. It is misbehavior of users.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we don't need to consider the 2nd case. It is misbehavior of users.

I think this is the case which rarely happens.
However, I don't think it is misbehavior of users. Since the user does not know whether it will cause panic or not.

However, again, as Database.Close is called after Blockchain.Stop, there is no possibility that Database.Put is called after Database.Close.

@joowon-byun joowon-byun merged commit acfcd55 into klaytn:dev Aug 19, 2020
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.

None yet

5 participants