Skip to content

Sugar syntax for acquiring a shard and logging the trace loop#123

Closed
aarshkshah1992 wants to merge 3 commits intomasterfrom
feat/common-utils
Closed

Sugar syntax for acquiring a shard and logging the trace loop#123
aarshkshah1992 wants to merge 3 commits intomasterfrom
feat/common-utils

Conversation

@aarshkshah1992
Copy link
Contributor

Just some sugar syntax to synchronously acquiring a shard and for logging the trace loop in debug mode.

@aarshkshah1992 aarshkshah1992 requested review from dirkmc and raulk June 7, 2022 06:50
handlers.go Outdated

// LogTraceLoop logs the output of the given trace channel until the given context expires.
func LogTraceLoop(ctx context.Context, traceCh chan Trace, onDone func()) {
defer onDone()
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure I understand why you need the onDone method here. Instead of passing this function as a parameter, can't the caller just do:

LogTraceLoop(ctx, ch)
onDone()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed this function completely.

handlers.go Outdated
}

// LogTraceLoop logs the output of the given trace channel until the given context expires.
func LogTraceLoop(ctx context.Context, traceCh chan Trace, onDone func()) {
Copy link
Member

Choose a reason for hiding this comment

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

This doesn't belong here. As a utility, this makes way too many assumptions: log level, message, etc. The leakage is obvious in the fact that you need to provide an onDone function as an argument.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed this.

helpers/shard.go Outdated
func AcquireShardSync(ctx context.Context, dagst *dagstore.DAGStore, sk shard.Key) (*dagstore.ShardAccessor, error) {
ch := make(chan dagstore.ShardResult, 1)

if err := dagst.AcquireShard(ctx, sk, ch, dagstore.AcquireOpts{}); err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

To make this a true utility function with no assumptions built-in, you should pass AcquireOpts as an argument.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

shard/key.go Outdated
}

// KeyFromCIDMultihash returns a key based on the multihash of the given cid.
func KeyFromCIDMultihash(cid cid.Cid) Key {
Copy link
Member

@raulk raulk Jun 7, 2022

Choose a reason for hiding this comment

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

Is it too hard to do this in the application? All other Key* functions are constructors. If anything, I'd make this a KeyFromMultihash and pass in the multihash directly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed this completely.

@aarshkshah1992
Copy link
Contributor Author

Review addressed and helper added in #128.

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.

3 participants