Skip to content

etcdserver, raft: cleanup raft.Storage interface and raft.MemoryStora…#8679

Closed
mitake wants to merge 1 commit into
etcd-io:masterfrom
mitake:raft-storage-cleanup
Closed

etcdserver, raft: cleanup raft.Storage interface and raft.MemoryStora…#8679
mitake wants to merge 1 commit into
etcd-io:masterfrom
mitake:raft-storage-cleanup

Conversation

@mitake

@mitake mitake commented Oct 11, 2017

Copy link
Copy Markdown
Contributor

…ge struct

This commit lets raft.MemoryStorage be private (the new name is simply
memoryStorage) for cleaner separation between packages. MemoryStorage
doesn't have global variable fields and external packages use it as an
object which implements raft.Storage in many cases. I think the struct
doesn't need to be a global thing.

I found the interface separation isn't clean enough during reworking #7782. To the best of my knowledge, making MemoryStorage private wouldn't be a problem.

@xiang90 xiang90 self-assigned this Oct 11, 2017
@gyuho

gyuho commented Oct 11, 2017

Copy link
Copy Markdown
Contributor

@mitake @xiang90 If we do this, commits should be separate?
One for raft, another for etcdserver?

@mitake

mitake commented Oct 12, 2017

Copy link
Copy Markdown
Contributor Author

@gyuho why? Separating would make the first commit not buildable?

@gyuho

gyuho commented Oct 12, 2017

Copy link
Copy Markdown
Contributor

I was worrying projects importing only raft packages, but it shouldn't be a problem. Never mind.

@mitake

mitake commented Oct 12, 2017

Copy link
Copy Markdown
Contributor Author

@gyuho I see. But putting changes in a single commit wouldn't be a problem for the case, I think (e.g. clientv3 is often changed with other packages). If it will cause troubles, of course I'll separate the commit.

@mitake mitake force-pushed the raft-storage-cleanup branch from b685695 to dfa18c1 Compare November 2, 2017 06:18
@mitake mitake force-pushed the raft-storage-cleanup branch 4 times, most recently from 0a033f2 to 071a38b Compare February 2, 2018 05:27
@mitake

mitake commented Feb 5, 2018

Copy link
Copy Markdown
Contributor Author

Rebased on the latest master. I couldn't reproduce the gosimple error https://travis-ci.org/coreos/etcd/jobs/336420586 on my local env. Also I can't see errors of the failed CI https://semaphoreci.com/coreos/etcd/branches/pull-request-8679/builds/6 ...

@gyuho

gyuho commented Feb 5, 2018

Copy link
Copy Markdown
Contributor

Defer to @xiang90

@mitake

mitake commented Feb 16, 2018

Copy link
Copy Markdown
Contributor Author

@gyuho could you trigger travis CI again? I can't reproduce the error on my local environment, it is strange...

@gyuho

gyuho commented Feb 16, 2018

Copy link
Copy Markdown
Contributor

@mitake Can you rebase from master? And force push? We upgraded Go version in travis as well. Thanks!

@mitake mitake force-pushed the raft-storage-cleanup branch from 071a38b to 2bc8541 Compare February 16, 2018 02:31
@mitake

mitake commented Feb 16, 2018

Copy link
Copy Markdown
Contributor Author

@gyuho thanks, rebased

@gyuho gyuho requested a review from xiang90 February 16, 2018 02:32
Comment thread raft/storage.go
// snapshot and call Snapshot later.
Snapshot() (pb.Snapshot, error)
// SetHardState saves the current HardState.
SetHardState(st pb.HardState) error

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.

I am not sure if this makes sense for other people. We do not want to enforce how write operations to be handled.

@bdarnell cockroach db probably has its own storage implementation that handles the write related operations in a different way.

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.

Yeah, Storage and MemoryStorage were separate by design. It's important for us that the Storage interface is read-only and all writes go through the Ready struct. This lets us do a better job of batching different writes together.

This change is also weird in that it adds a bunch of methods to the Storage interface that we'd have to implement, but it doesn't add any non-test callers of them.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I see, thanks for pointing out the problem. I'll consider how to do it without disrupting existing users of the raft package.

…ge struct

This commit lets raft.MemoryStorage be private (the new name is simply
memoryStorage) for cleaner separation between packages. MemoryStorage
doesn't have global variable fields and external packages use it as an
object which implements raft.Storage in many cases. I think the struct
doesn't need to be a global thing.
@mitake mitake force-pushed the raft-storage-cleanup branch from 2bc8541 to 90076a0 Compare February 16, 2018 05:31
@codecov-io

Copy link
Copy Markdown

Codecov Report

❗ No coverage uploaded for pull request base (master@b03fd4c). Click here to learn what that means.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff            @@
##             master    #8679   +/-   ##
=========================================
  Coverage          ?   75.63%           
=========================================
  Files             ?      365           
  Lines             ?    30720           
  Branches          ?        0           
=========================================
  Hits              ?    23234           
  Misses            ?     5866           
  Partials          ?     1620
Impacted Files Coverage Δ
raft/storage.go 88.18% <100%> (ø)
etcdserver/server.go 79.37% <100%> (ø)
etcdserver/raft.go 89.22% <100%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b03fd4c...90076a0. Read the comment docs.

Comment thread raft/storage.go
// snapshot and call Snapshot later.
Snapshot() (pb.Snapshot, error)
// SetHardState saves the current HardState.
SetHardState(st pb.HardState) error

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.

Yeah, Storage and MemoryStorage were separate by design. It's important for us that the Storage interface is read-only and all writes go through the Ready struct. This lets us do a better job of batching different writes together.

This change is also weird in that it adds a bunch of methods to the Storage interface that we'd have to implement, but it doesn't add any non-test callers of them.

@xiang90

xiang90 commented Jan 9, 2019

Copy link
Copy Markdown
Contributor

closing this as @bdarnell suggested.

@xiang90 xiang90 closed this Jan 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

5 participants