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

feat: pullstorage iterator share #1891

Merged
merged 6 commits into from
May 28, 2021
Merged

Conversation

janos
Copy link
Member

@janos janos commented May 27, 2021

This is an alternative approach to share pullstorage iterators by using resenje.org/singleflight which is context aware compared to the x/sync/singleflight implementation. The relevant functionality is described here https://pkg.go.dev/resenje.org/singleflight#Group.Do.

Currently, this is just a POC, unit tests should be added before merging.


This change is Reviewable

@janos janos force-pushed the pullstorage-iterator-share branch from 91b0264 to f98861d Compare May 27, 2021 21:48
@janos janos requested review from acud and aloknerurkar May 27, 2021 22:39
Copy link
Contributor

@aloknerurkar aloknerurkar left a comment

Choose a reason for hiding this comment

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

Can we add a test here for IntervalChunks function? I think you can use the first test I have for IteratorShare. Although there seem to be enough tests in the lib to verify, it will be good to have one in this package.

@aloknerurkar aloknerurkar requested a review from istae May 28, 2021 09:29
Copy link
Contributor

@mrekucci mrekucci left a comment

Choose a reason for hiding this comment

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

Reviewed 3 of 3 files at r1, 2 of 2 files at r2, 1 of 1 files at r3.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @acud, @esadakar, and @janos)


pkg/pullsync/pullstorage/pullstorage_test.go, line 313 at r2 (raw file):

		// delay is needed in order to have the iterator
		// linger for a bit longer for more chunks.
		<-time.After(200 * time.Millisecond)

Using time.Sleep would be more efficient.


pkg/pullsync/pullstorage/pullstorage_test.go, line 356 at r2 (raw file):

	}

	// check that results point to same array

Examine the internal is dangerous since you're relying on assumptions that might not be true in the feature. I'd recommend comparing the content of these arrays directly; if you want to save some lines I'd recommend using: https://github.com/google/go-cmp for that (It checks for Equal method, not like reflect.DeepEqual).


pkg/pullsync/pullstorage/pullstorage_test.go, line 436 at r2 (raw file):

				}
				// check that results point to same array
				sh := (*reflect.SliceHeader)(unsafe.Pointer(&res.addrs))

The same as above.

@aloknerurkar
Copy link
Contributor


pkg/pullsync/pullstorage/pullstorage_test.go, line 356 at r2 (raw file):

Previously, mrekucci (Peter Mrekaj) wrote…

Examine the internal is dangerous since you're relying on assumptions that might not be true in the feature. I'd recommend comparing the content of these arrays directly; if you want to save some lines I'd recommend using: https://github.com/google/go-cmp for that (It checks for Equal method, not like reflect.DeepEqual).

This verifies the feature. If we get multiple similar requests for IntervalChunks we should get a shared result. This result is used for readOnly.

Copy link
Contributor

@mrekucci mrekucci left a comment

Choose a reason for hiding this comment

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

Reviewed 1 of 1 files at r4.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @acud and @esadakar)


pkg/pullsync/pullstorage/pullstorage_test.go, line 356 at r2 (raw file):

Previously, aloknerurkar (Alok Nerurkar) wrote…

This verifies the feature. If we get multiple similar requests for IntervalChunks we should get a shared result. This result is used for readOnly.

I'm concern that the values wouldn't be the same. I don't know whether this shared iterator should also prevent doing that. Because we're using mutable addresses and if one goroutine shares a slice with another even they are pointing to the same top slice, because of the mutable nature, the content in time can be different.

Copy link
Contributor

@mrekucci mrekucci left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @acud and @esadakar)

@aloknerurkar aloknerurkar merged commit 1b0839d into master May 28, 2021
@aloknerurkar aloknerurkar deleted the pullstorage-iterator-share branch May 28, 2021 11:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants