mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-04 10:07:28 +01:00
* mq: keep keyless and valueless messages in compacted parquet mq.topic.compact treated every message without a key, every message without a value, and every value that happened to parse as a DataMessage with a Ctrl as a control entry, and left it out of the parquet it wrote. Kafka records with a null key and tombstones were gone once retention removed their logs, and so was a JSON string value whose bytes parse that way. The only control entry a log holds is a publisher's close marker, which the broker logged without its Ctrl, as an entry with neither key nor value. That is now the whole rule, for compaction and for reading parquet back. A schematized topic's message without a value is still left out, since its row has no column to hold one. Claude-Session: https://claude.ai/code/session_011Upvai5AjLiNE5B1HCAn34 * mq broker: ack a publisher's close marker without logging it The marker a publisher sends when it finishes was appended to the partition log like a message, minus its Ctrl, so it took an offset and sat in the log as an entry with neither key nor value that every reader had to recognize and skip. The broker now acks it and moves on. Every message the publisher sent before it on the stream was acked first, so the publisher's wait for its last ack is unchanged. Logs written before still hold markers, which readers keep skipping. Claude-Session: https://claude.ai/code/session_011Upvai5AjLiNE5B1HCAn34 * mq broker: log a Ctrl message that carries a key or value The close-marker branch dropped every DataMessage with a Ctrl, though one carrying a key or value was published before. Only a bare marker, a Ctrl with neither, is acked without an offset now; anything else is stored at its offset as it was. Claude-Session: https://claude.ai/code/session_011Upvai5AjLiNE5B1HCAn34 * query engine: skip only close markers, as compaction does Compaction now keeps keyless messages and values that happen to parse as a DataMessage with a Ctrl, but the SQL engine still dropped both from log scans and live-log counts, while COUNT(*) took parquet row counts from file stats. After compaction COUNT(*) included messages SELECT did not show. Scans and counts now use the same rule as compaction and parquet reads. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * query engine: leave out a schematized message without a value, as compaction does Compaction writes no row for a schematized message without a value, so a live log count that included one dropped by one once its log was compacted. Scans and live-log counts now skip what compaction skips. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * query engine: count only rows among broker-buffered messages The COUNT(*) fast path added every unflushed broker message, so a close marker or a schematized message without a value counted until its flush, when the live-log count left it out. Unflushed messages now count by the same row rule. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * query engine: test the broker-buffered count against the scan COUNT(*) adds the broker's unflushed messages by the row rule a scan of them uses, but nothing tested it. The count moves into countRows, and the scan test checks it gives the number of rows the scan returns for a schemaless and a schematized topic, so close markers and schematized messages without a value stay out of both. Claude-Session: https://claude.ai/code/session_011Upvai5AjLiNE5B1HCAn34 --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
76 lines
2.4 KiB
Go
76 lines
2.4 KiB
Go
package engine
|
|
|
|
import (
|
|
"context"
|
|
"slices"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/mq/topic"
|
|
"github.com/seaweedfs/seaweedfs/weed/pb/filer_pb"
|
|
"github.com/seaweedfs/seaweedfs/weed/pb/schema_pb"
|
|
)
|
|
|
|
type unflushedEntriesBroker struct {
|
|
BrokerClientInterface
|
|
entries []*filer_pb.LogEntry
|
|
}
|
|
|
|
func (b *unflushedEntriesBroker) GetUnflushedMessages(context.Context, string, string, topic.Partition, int64) ([]*filer_pb.LogEntry, error) {
|
|
return b.entries, nil
|
|
}
|
|
|
|
// A query sees the rows compaction keeps: a close marker, an entry with
|
|
// neither key nor value, is not one, and in a schematized topic neither is a
|
|
// message without a value.
|
|
func TestScanSkipsWhatCompactionSkips(t *testing.T) {
|
|
// a JSON string whose bytes parse as a DataMessage carrying a Ctrl
|
|
jsonString := []byte(`" ` + strings.Repeat("h1", 15) + `h"`)
|
|
entries := []*filer_pb.LogEntry{
|
|
{TsNs: 1, Data: []byte("keyless")},
|
|
{TsNs: 2, Key: []byte("tombstone")},
|
|
{TsNs: 3, Key: []byte("json"), Data: jsonString},
|
|
{TsNs: 4},
|
|
{TsNs: 5, Key: []byte("k"), Data: []byte("v")},
|
|
}
|
|
bytesType := &schema_pb.Type{Kind: &schema_pb.Type_ScalarType{ScalarType: schema_pb.ScalarType_BYTES}}
|
|
for _, tc := range []struct {
|
|
name string
|
|
fields []*schema_pb.Field
|
|
want []int64
|
|
}{
|
|
{"schemaless", []*schema_pb.Field{{Name: SW_COLUMN_NAME_VALUE, Type: bytesType}}, []int64{1, 2, 3, 5}},
|
|
{"schematized", []*schema_pb.Field{{Name: "payload", Type: bytesType}}, []int64{1, 3, 5}},
|
|
} {
|
|
hms := &HybridMessageScanner{
|
|
brokerClient: &unflushedEntriesBroker{entries: entries},
|
|
topic: topic.Topic{Namespace: "ns", Name: "t"},
|
|
recordSchema: &schema_pb.RecordType{Fields: tc.fields},
|
|
}
|
|
results, _, err := hms.scanUnflushedDataWithStats(context.Background(), topic.Partition{}, HybridScanOptions{})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
var got []int64
|
|
for _, r := range results {
|
|
got = append(got, r.Timestamp)
|
|
}
|
|
if !slices.Equal(got, tc.want) {
|
|
t.Errorf("%s: scanned messages at %v, want %v", tc.name, got, tc.want)
|
|
}
|
|
var rows []int64
|
|
for _, e := range entries {
|
|
if hms.isRow(e) {
|
|
rows = append(rows, e.TsNs)
|
|
}
|
|
}
|
|
if !slices.Equal(rows, tc.want) {
|
|
t.Errorf("%s: counted rows at %v, want %v", tc.name, rows, tc.want)
|
|
}
|
|
// COUNT(*) adds the broker's unflushed entries by the same rule
|
|
if got := hms.countRows(entries); got != int64(len(tc.want)) {
|
|
t.Errorf("%s: %d unflushed rows counted, the scan reads %d", tc.name, got, len(tc.want))
|
|
}
|
|
}
|
|
}
|