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

fix: fix logstream state #101

Merged
merged 1 commit into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 15 additions & 14 deletions pkg/collectconfig/executor/inputsmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,30 +42,29 @@ func (im *inputsManager) checkInputsChange() {
newInputs := make(map[string]*inputWrapper, len(paths))

for _, fatPath := range paths {
path := fatPath.Path
key := logstream.BuildFileKey(fatPath.Path, fatPath.Attrs)
// deduplication
if _, ok := usedPaths[path]; ok {
if _, ok := usedPaths[key]; ok {
continue
}
usedPaths[path] = struct{}{}
usedPaths[key] = struct{}{}

if iw, ok := im.inputs[path]; ok {
newInputs[path] = iw
if iw, ok := im.inputs[key]; ok {
newInputs[key] = iw
} else {
// create if not exist
logger.Infoz("[pipeline] [log] [input] add", //
zap.String("key", im.key), //
zap.String("path", path))
zap.String("path", key))

var ls logstream.LogStream

if fatPath.IsSls {
ls = im.lsm.AcquireSls(fatPath.SlsConfig)
} else {
ls = im.lsm.AcquireFile(path, fatPath.Attrs)
ls = im.lsm.AcquireFile(fatPath.Path, fatPath.Attrs)
}

newInputs[path] = &inputWrapper{
newInputs[key] = &inputWrapper{
ls: ls,
inputStateObj: inputStateObj{
FatPath: fatPath,
Expand All @@ -77,13 +76,15 @@ func (im *inputsManager) checkInputsChange() {
}
}

for path := range im.inputs {
if _, ok := newInputs[path]; !ok {
for key := range im.inputs {
if _, ok := newInputs[key]; !ok {
// 删除那些不再匹配的
im.releaseStream(im.inputs[path])
logger.Infoz("[pipeline] [log] [input] input", //
im.releaseStream(im.inputs[key])
logger.Infoz("[pipeline] [log] [input] remove input", //
zap.String("key", im.key), //
zap.String("path", path))
zap.String("path", key),
zap.Any("new", paths),
)
}
}

Expand Down
8 changes: 7 additions & 1 deletion pkg/collectconfig/executor/logstream/logstream_g.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@ func (f *GLogStream) getFromCache(cursor int64) *ReadResponse {
}

func (f *GLogStream) Read(reqCursor int64) (*ReadResponse, int64, error) {
//logger.Debugz("debug read",
// zap.Uintptr("f", uintptr(unsafe.Pointer(f))),
// zap.String("key", f.Key),
// zap.Int64("cursor", reqCursor),
// zap.Int("listeners", len(f.Listeners)))

// check cache
if c := f.getFromCache(reqCursor); c != nil {
return c, c.Cursor + 1, c.error
Expand Down Expand Up @@ -159,7 +165,7 @@ func (f *GLogStream) RemoveListener(listener Listener, cursor int64) {
}
}
if x := len(f.Listeners) - len(listeners); x > 1 {
logger.Errorz("remove multi listeners", zap.String("key", f.Key), zap.Int("old", len(f.Listeners)), zap.Int("new", len(listeners)))
logger.Errorz("remove multi listeners", zap.String("key", f.Key), zap.Int("old", len(f.Listeners)), zap.Int("new", len(listeners)), zap.Stack("stack"))
}
f.Listeners = listeners

Expand Down
4 changes: 4 additions & 0 deletions pkg/collectconfig/executor/logstream/logstream_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,10 @@ func (m *Manager) AcquireFile(path string, attrs map[string]string) LogStream {
return m.acquire0(path, attrs, nil)
}

func BuildFileKey(path string, attrs map[string]string) string {
return buildFileKey(path, attrs)
}

func buildFileKey(path string, attrs map[string]string) string {
if len(attrs) == 0 {
return path
Expand Down
4 changes: 2 additions & 2 deletions pkg/cri/impl/default_cri.go
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,7 @@ func (e *defaultCri) buildCriContainer(criPod *cri.Pod, dc *cri.EngineDetailCont

criPod.All = append(criPod.All, criContainer)

if criContainer.IsRunning() && criContainer.Hacked == cri.HackInit && !criContainer.Sandbox {
if criContainer.IsRunning() && criContainer.Hacked == cri.HackInit && criContainer.MainBiz {
criContainer.Hacked = cri.HackIng

var err error
Expand Down Expand Up @@ -935,7 +935,7 @@ func (e *defaultCri) buildPod(pod *v1.Pod, oldState *internalState, newState *in
if cached != nil && !isContainerChanged(cached.engineContainer, container) {
cached.criContainer.Pod = criPod

if forceUpdateContainerInfo {
if forceUpdateContainerInfo && cached.criContainer.MainBiz {
go e.updateZombieCheck(cached.criContainer)
}

Expand Down
Loading