-
Notifications
You must be signed in to change notification settings - Fork 144
CBG-5184 use cbgt one shot mode #8266
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
Open
torcolvin
wants to merge
10
commits into
main
Choose a base branch
from
CBG-5184
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
662f58c
CBG-5184 add support for cbgt stopping after a sequence
torcolvin e22a3ca
Fix warning message
torcolvin aabbddd
add reset function
torcolvin 7113953
Add TODO
torcolvin 52c68f2
Merge remote-tracking branch 'origin/main' into CBG-5184
torcolvin 435b6be
Enable tests
torcolvin 4339186
fix checkpointing
torcolvin abcd258
update comment
torcolvin 7376c66
Merge remote-tracking branch 'origin/main' into CBG-5184
torcolvin 6116307
setup processing sequence
torcolvin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,6 +30,7 @@ func init() { | |
| type SGDest interface { | ||
| cbgt.Dest | ||
| cbgt.DestEx | ||
| ForceCheckpointWrite() | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As discussed, PR doesn't currently have any callers of ForceCheckpointWrite. Review whether that's intentional. |
||
| } | ||
|
|
||
| // DCPDest implements SGDest (superset of cbgt.Dest) interface to manage updates coming from a | ||
|
|
@@ -41,28 +42,32 @@ type DCPDest struct { | |
| metaInitComplete []bool // Whether metadata initialization has been completed, per vbNo | ||
| } | ||
|
|
||
| // NewDCPDest creates a new DCPDest which manages updates coming from a cbgt-based DCP feed. The callback function will receive events from a DCP feed. If persistCheckpoints is true, stores checkpoints as documents in metadataStore starting with checkpointPrefix. | ||
| // Specific stats for DCP are stored in expvars rather than SgwStats, except for partition stat, which indicates the number of cbgt partitions assigned to this node. | ||
| type DCPDestOptions struct { | ||
| Callback sgbucket.FeedEventCallbackFunc // Callback function receives DCP events. | ||
| MetadataStore sgbucket.DataStore // location to store checkpoints in | ||
| MaxVbNo uint16 // number of vBuckets for the backing bucket (does not have to match metadata store) | ||
| PersistCheckpoints bool // if true, write checkpoints to MetadataStore with keys prefixed by CheckpointPrefix | ||
| DcpStats *expvar.Map // Optional stats for dcp_rollback_count. This is not exposed by prometheus. | ||
| PartitionStat *SgwIntStat // Optional stat for active partition count, to track cbgt partitions. | ||
| CheckpointPrefix string // document prefix for checkpoint documents. | ||
| EndSeqNos map[uint16]uint64 // If running a one shot DCP feed, these should match the end sequence numbers for each vbNo. | ||
| } | ||
|
|
||
| // NewDCPDest creates a new DCPDest which manages updates coming from a cbgt-based DCP feed. | ||
| // Each partition will have its own DCPDest object. | ||
| func NewDCPDest( | ||
| ctx context.Context, | ||
| callback sgbucket.FeedEventCallbackFunc, | ||
| metadataStore sgbucket.DataStore, | ||
| maxVbNo uint16, | ||
| persistCheckpoints bool, | ||
| dcpStats *expvar.Map, | ||
| partitionStat *SgwIntStat, | ||
| checkpointPrefix string, | ||
| opts DCPDestOptions, | ||
| ) (SGDest, error) { | ||
|
torcolvin marked this conversation as resolved.
|
||
| dcpCommon, err := NewDCPCommon(ctx, callback, metadataStore, maxVbNo, persistCheckpoints, dcpStats, checkpointPrefix) | ||
| dcpCommon, err := NewDCPCommon(ctx, opts) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| d := &DCPDest{ | ||
| DCPCommon: dcpCommon, | ||
| partitionCountStat: partitionStat, | ||
| metaInitComplete: make([]bool, maxVbNo), | ||
| partitionCountStat: opts.PartitionStat, | ||
| metaInitComplete: make([]bool, opts.MaxVbNo), | ||
| } | ||
|
|
||
| if d.partitionCountStat != nil { | ||
|
|
@@ -213,7 +218,7 @@ func (d *DCPDest) RollbackEx(partition string, vbucketUUID uint64, rollbackSeq u | |
|
|
||
| // TODO: Not implemented, review potential usage | ||
| func (d *DCPDest) ConsistencyWait(partition, partitionUUID string, | ||
| consistencyLevel string, consistencySeq uint64, cancelCh <-chan bool) error { | ||
| consistencyLevel cbgt.ConsistencyLevel, consistencySeq uint64, cancelCh <-chan bool) error { | ||
| WarnfCtx(d.loggingCtx, "Dest.ConsistencyWait being invoked by cbgt - not supported by Sync Gateway") | ||
| return nil | ||
| } | ||
|
|
@@ -234,6 +239,23 @@ func (d *DCPDest) Stats(io.Writer) error { | |
| return nil | ||
| } | ||
|
|
||
| // ForceCheckpointWrite forces a write on all checkpoints. | ||
| func (d *DCPDest) ForceCheckpointWrite() { | ||
| for vbNo, init := range d.metaInitComplete { | ||
| if init { | ||
| value, _, err := d.getMetaData(uint16(vbNo)) | ||
| if err != nil { | ||
| WarnfCtx(d.loggingCtx, "Could not retrieve metadata for vbNo %d during ForceCheckpointWrite: %v. Skipping checkpoint write", vbNo, err) | ||
| continue | ||
| } | ||
| err = d.setMetaData(uint16(vbNo), value, true) | ||
| if err != nil { | ||
| WarnfCtx(d.loggingCtx, "Could not persist metadata for vbNo %d during ForceCheckpointWrite: %v. Skipping checkpoint write", vbNo, err) | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| func partitionToVbNo(ctx context.Context, partition string) uint16 { | ||
| vbNo, err := strconv.Atoi(partition) | ||
| if err != nil { | ||
|
|
@@ -316,7 +338,7 @@ func (d *DCPLoggingDest) RollbackEx(partition string, vbucketUUID uint64, rollba | |
| } | ||
|
|
||
| func (d *DCPLoggingDest) ConsistencyWait(partition, partitionUUID string, | ||
| consistencyLevel string, consistencySeq uint64, cancelCh <-chan bool) error { | ||
| consistencyLevel cbgt.ConsistencyLevel, consistencySeq uint64, cancelCh <-chan bool) error { | ||
| return d.dest.ConsistencyWait(partition, partitionUUID, consistencyLevel, consistencySeq, cancelCh) | ||
| } | ||
|
|
||
|
|
@@ -332,3 +354,10 @@ func (d *DCPLoggingDest) Query(pindex *cbgt.PIndex, req []byte, w io.Writer, | |
| func (d *DCPLoggingDest) Stats(w io.Writer) error { | ||
| return d.dest.Stats(w) | ||
| } | ||
|
|
||
| func (d *DCPLoggingDest) ForceCheckpointWrite() { | ||
| d.dest.ForceCheckpointWrite() | ||
| } | ||
|
|
||
| var _ SGDest = &DCPDest{} | ||
| var _ SGDest = &DCPLoggingDest{} | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we do this check earlier (in dataUpdate) and also avoid callback processing for any sequences higher than endSeqNo?