-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
113 additions
and
2 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ | |
.pkg | ||
.cache | ||
cmd/distributor/distributor | ||
cmd/ingester/ingester |
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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package ingester | ||
|
||
import ( | ||
"github.com/grafana/logish/pkg/logproto" | ||
"github.com/pkg/errors" | ||
) | ||
|
||
const ( | ||
tmpNumEntries = 1024 | ||
) | ||
|
||
var ( | ||
ErrChunkFull = errors.New("Chunk full") | ||
ErrOutOfOrder = errors.New("Entry out of order") | ||
) | ||
|
||
type Chunk interface { | ||
SpaceFor(*logproto.Entry) bool | ||
Push(*logproto.Entry) error | ||
} | ||
|
||
func newChunk() Chunk { | ||
return &dumbChunk{} | ||
} | ||
|
||
type dumbChunk struct { | ||
entries []*logproto.Entry | ||
} | ||
|
||
func (c *dumbChunk) SpaceFor(_ *logproto.Entry) bool { | ||
return len(c.entries) == tmpNumEntries | ||
} | ||
|
||
func (c *dumbChunk) Push(entry *logproto.Entry) error { | ||
if len(c.entries) == tmpNumEntries { | ||
return ErrChunkFull | ||
} | ||
|
||
if len(c.entries) > 0 && c.entries[len(c.entries)-1].Timestamp.After(entry.Timestamp) { | ||
return ErrOutOfOrder | ||
} | ||
|
||
c.entries = append(c.entries, entry) | ||
return nil | ||
} |
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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package ingester | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/grafana/logish/pkg/logproto" | ||
) | ||
|
||
const tmpMaxChunks = 3 | ||
|
||
type stream struct { | ||
// Newest chunk at chunks[0]. | ||
// Not thread-safe; assume accesses to this are locked by caller. | ||
chunks []Chunk | ||
} | ||
|
||
func newStream() *stream { | ||
return &stream{} | ||
} | ||
|
||
func (s *stream) Push(ctx context.Context, entries []logproto.Entry) error { | ||
if len(s.chunks) == 0 { | ||
s.chunks = append(s.chunks, newChunk()) | ||
} | ||
|
||
for i := range entries { | ||
if !s.chunks[0].SpaceFor(&entries[i]) { | ||
s.chunks = append([]Chunk{newChunk()}, s.chunks...) | ||
} | ||
if err := s.chunks[0].Push(&entries[i]); err != nil { | ||
return err | ||
} | ||
} | ||
|
||
// Temp; until we implement flushing, only keep N chunks in memory. | ||
if len(s.chunks) > tmpMaxChunks { | ||
s.chunks = s.chunks[:tmpMaxChunks] | ||
} | ||
return nil | ||
} |
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