-
Notifications
You must be signed in to change notification settings - Fork 113
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: optimize route switching when freeze segment #321
Draft
hwjiangkai
wants to merge
7
commits into
main
Choose a base branch
from
segment
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.
+1,371
−833
Draft
Changes from 2 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
9c505cc
feat: Optimize the routing logic for segment full
hwjiangkai 074e7f9
fix review
hwjiangkai 9351af1
feat: fix review comments
hwjiangkai 88c1479
Merge branch 'main' of github.com:linkall-labs/vanus into segment
hwjiangkai 5b3b241
feat: fix review comments
hwjiangkai 8b9f873
Merge branch 'main' of github.com:linkall-labs/vanus into segment
hwjiangkai 8c06b70
fix review comments
hwjiangkai 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 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 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 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 |
---|---|---|
|
@@ -17,8 +17,6 @@ package eventbus | |
import ( | ||
// standard libraries. | ||
"context" | ||
"encoding/base64" | ||
"encoding/binary" | ||
stderrors "errors" | ||
"io" | ||
"strings" | ||
|
@@ -37,7 +35,7 @@ import ( | |
"github.com/linkall-labs/vanus/client/pkg/errors" | ||
"github.com/linkall-labs/vanus/client/pkg/eventlog" | ||
"github.com/linkall-labs/vanus/client/pkg/policy" | ||
vlog "github.com/linkall-labs/vanus/observability/log" | ||
"github.com/linkall-labs/vanus/observability/log" | ||
|
||
eb "github.com/linkall-labs/vanus/client/internal/vanus/eventbus" | ||
el "github.com/linkall-labs/vanus/client/internal/vanus/eventlog" | ||
|
@@ -66,7 +64,7 @@ func NewEventbus(cfg *eb.Config) *eventbus { | |
for { | ||
re, ok := <-ch | ||
if !ok { | ||
vlog.Debug(context.Background(), "eventbus quits writable watcher", map[string]interface{}{ | ||
log.Debug(context.Background(), "eventbus quits writable watcher", map[string]interface{}{ | ||
"eventbus": bus.cfg.Name, | ||
}) | ||
break | ||
|
@@ -88,7 +86,7 @@ func NewEventbus(cfg *eb.Config) *eventbus { | |
for { | ||
re, ok := <-ch | ||
if !ok { | ||
vlog.Debug(context.Background(), "eventbus quits readable watcher", map[string]interface{}{ | ||
log.Debug(context.Background(), "eventbus quits readable watcher", map[string]interface{}{ | ||
"eventbus": bus.cfg.Name, | ||
}) | ||
break | ||
|
@@ -187,16 +185,16 @@ func (b *eventbus) GetLog(ctx context.Context, logID uint64, opts ...api.LogOpti | |
if len(b.readableLogs) == 0 { | ||
ifplusor marked this conversation as resolved.
Show resolved
Hide resolved
|
||
b.refreshReadableLogs(ctx) | ||
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. unlock when refresh route info. |
||
} | ||
if log, ok := b.readableLogs[logID]; ok { | ||
return log, nil | ||
if l, ok := b.readableLogs[logID]; ok { | ||
ifplusor marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return l, nil | ||
} | ||
return nil, errors.ErrNotFound | ||
} else if op.Policy.AccessMode() == api.ReadWrite { | ||
if len(b.writableLogs) == 0 { | ||
ifplusor marked this conversation as resolved.
Show resolved
Hide resolved
|
||
b.refreshWritableLogs(ctx) | ||
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. unlock when refresh route info. |
||
} | ||
if log, ok := b.writableLogs[logID]; ok { | ||
return log, nil | ||
if l, ok := b.writableLogs[logID]; ok { | ||
ifplusor marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return l, nil | ||
} | ||
return nil, errors.ErrNotFound | ||
} else { | ||
|
@@ -312,8 +310,8 @@ func (b *eventbus) updateWritableLogs(ctx context.Context, re *WritableLogsResul | |
Endpoints: b.cfg.Endpoints, | ||
ID: logID, | ||
} | ||
log := eventlog.NewEventLog(cfg) | ||
lws[logID] = log | ||
l := eventlog.NewEventLog(cfg) | ||
lws[logID] = l | ||
return true | ||
}) | ||
b.setWritableLogs(s, lws) | ||
|
@@ -407,8 +405,8 @@ func (b *eventbus) updateReadableLogs(ctx context.Context, re *ReadableLogsResul | |
Endpoints: b.cfg.Endpoints, | ||
ID: logID, | ||
} | ||
log := eventlog.NewEventLog(cfg) | ||
lws[logID] = log | ||
l := eventlog.NewEventLog(cfg) | ||
lws[logID] = l | ||
return true | ||
}) | ||
b.setReadableLogs(s, lws) | ||
|
@@ -451,7 +449,7 @@ type busWriter struct { | |
|
||
var _ api.BusWriter = (*busWriter)(nil) | ||
|
||
func (w *busWriter) AppendOne(ctx context.Context, event *ce.Event, opts ...api.WriteOption) (eid string, err error) { | ||
func (w *busWriter) AppendOne(ctx context.Context, event *ce.Event, opts ...api.WriteOption) (string, error) { | ||
_ctx, span := w.tracer.Start(ctx, "AppendOne") | ||
defer span.End() | ||
|
||
|
@@ -470,21 +468,15 @@ func (w *busWriter) AppendOne(ctx context.Context, event *ce.Event, opts ...api. | |
} | ||
|
||
// 2. append the event to the eventlog | ||
off, err := lw.Append(_ctx, event) | ||
eid, err := lw.Append(_ctx, event) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
// 3. generate event ID | ||
var buf [16]byte | ||
binary.BigEndian.PutUint64(buf[0:8], lw.Log().ID()) | ||
binary.BigEndian.PutUint64(buf[8:16], uint64(off)) | ||
encoded := base64.StdEncoding.EncodeToString(buf[:]) | ||
|
||
return encoded, nil | ||
return eid, nil | ||
} | ||
|
||
func (w *busWriter) AppendMany(ctx context.Context, events []*ce.Event, opts ...api.WriteOption) (eid string, err error) { | ||
func (w *busWriter) AppendMany(ctx context.Context, events []*ce.Event, opts ...api.WriteOption) (string, error) { | ||
// TODO(jiangkai): implement this method, by jiangkai, 2022.10.24 | ||
return "", nil | ||
} | ||
|
@@ -497,17 +489,17 @@ func (w *busWriter) pickWritableLog(ctx context.Context, opts *api.WriteOptions) | |
_ctx, span := w.tracer.Start(ctx, "pickWritableLog") | ||
defer span.End() | ||
|
||
log, err := opts.Policy.NextLog(ctx) | ||
l, err := opts.Policy.NextLog(ctx) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
l := w.ebus.getWritableLog(_ctx, log.ID()) | ||
if l == nil { | ||
lw := w.ebus.getWritableLog(_ctx, l.ID()) | ||
if lw == nil { | ||
return nil, stderrors.New("can not pick writable log") | ||
} | ||
|
||
return l.Writer(), nil | ||
return lw.Writer(), nil | ||
} | ||
|
||
type busReader struct { | ||
|
@@ -558,11 +550,11 @@ func (r *busReader) pickReadableLog(ctx context.Context, opts *api.ReadOptions) | |
_ctx, span := r.tracer.Start(ctx, "pickReadableLog") | ||
defer span.End() | ||
|
||
log, err := opts.Policy.NextLog(ctx) | ||
l, err := opts.Policy.NextLog(ctx) | ||
if err != nil { | ||
return nil, err | ||
} | ||
lr := r.ebus.getReadableLog(_ctx, log.ID()) | ||
lr := r.ebus.getReadableLog(_ctx, l.ID()) | ||
if lr == nil { | ||
return nil, stderrors.New("can not pick readable log") | ||
} | ||
|
This file contains 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.
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.
must return
([]string, error)
.