intermediate

pull/9150/head
Ben Johnson 2017-10-25 07:29:44 -06:00
parent 919f99f34d
commit 3034d3fb54
No known key found for this signature in database
GPG Key ID: 81741CD251883081
3 changed files with 27 additions and 67 deletions

View File

@ -468,42 +468,6 @@ func (f *LogFile) AddSeriesList(names [][]byte, tagsSlice []models.Tags) error {
return nil
}
/*
// AddSeries adds a series to the log file.
func (f *LogFile) AddSeries(name []byte, tags models.Tags) error {
seriesID, err := f.sfile.CreateSeriesIfNotExists(name, tags, nil)
if err != nil {
return err
}
f.mu.Lock()
defer f.mu.Unlock()
e := LogEntry{SeriesID: seriesID}
if err := f.appendEntry(&e); err != nil {
return err
}
f.execEntry(&e)
return nil
}
*/
// DeleteSeries adds a tombstone for a series to the log file.
func (f *LogFile) DeleteSeriesID(seriesID uint64) error {
if seriesID == 0 {
return nil
}
f.mu.Lock()
defer f.mu.Unlock()
e := LogEntry{Flag: LogEntrySeriesTombstoneFlag, SeriesID: seriesID}
if err := f.appendEntry(&e); err != nil {
return err
}
f.execEntry(&e)
return nil
}
// SeriesN returns the total number of series in the file.
func (f *LogFile) SeriesN() (n uint64) {
f.mu.RLock()
@ -656,9 +620,6 @@ func (f *LogFile) execDeleteTagValueEntry(e *LogEntry) {
}
func (f *LogFile) execSeriesEntry(e *LogEntry) {
// Check if series is deleted.
deleted := (e.Flag & LogEntrySeriesTombstoneFlag) != 0
seriesKey := f.sfile.SeriesKey(e.SeriesID)
assert(seriesKey != nil, "series key not found")
@ -669,14 +630,6 @@ func (f *LogFile) execSeriesEntry(e *LogEntry) {
name, remainder := ReadSeriesKeyMeasurement(remainder)
mm := f.createMeasurementIfNotExists(name)
// Undelete measurement if it's been tombstoned previously.
if !deleted && mm.deleted {
mm.deleted = false
}
// Mark series id tombstone.
mm.series[e.SeriesID] = deleted
// Read tag count.
tagN, remainder := ReadSeriesKeyTagN(remainder)
@ -688,19 +641,12 @@ func (f *LogFile) execSeriesEntry(e *LogEntry) {
tv := ts.createTagValueIfNotExists(v)
// Add a reference to the series on the tag value.
tv.series[e.SeriesID] = deleted
tv.series[e.SeriesID] = struct{}{}
ts.tagValues[string(v)] = tv
mm.tagSet[string(k)] = ts
}
// Update the sketches.
if deleted {
// TODO(edd) decrement series count...
f.sTSketch.Add(seriesKey) // Deleting series so update tombstone sketch.
return
}
// TODO(edd) increment series count....
f.sSketch.Add(seriesKey) // Add series to sketch.
f.mSketch.Add(name) // Add measurement to sketch as this may be the fist series for the measurement.
@ -718,8 +664,8 @@ func (f *LogFile) SeriesIDIterator() SeriesIDIterator {
for _, mm := range f.mms {
n += len(mm.series)
a := make([]SeriesIDElem, 0, len(mm.series))
for seriesID, deleted := range mm.series {
a = append(a, SeriesIDElem{SeriesID: seriesID, Deleted: deleted})
for seriesID := range mm.series {
a = append(a, SeriesIDElem{SeriesID: seriesID})
}
sort.Sort(SeriesIDElems(a))
mSeries = append(mSeries, a)
@ -1093,7 +1039,6 @@ func appendLogEntry(dst []byte, e *LogEntry) []byte {
type logSerie struct {
name []byte
tags models.Tags
deleted bool
}
func (s *logSerie) String() string {
@ -1136,7 +1081,7 @@ type logMeasurement struct {
name []byte
tagSet map[string]logTagKey
deleted bool
series map[uint64]bool
series map[uint64]struct{}{}
}
func (mm *logMeasurement) seriesIDs() []uint64 {
@ -1225,7 +1170,7 @@ func (a logTagKeySlice) Less(i, j int) bool { return bytes.Compare(a[i].name, a[
type logTagValue struct {
name []byte
deleted bool
series map[uint64]bool
series map[uint64]struct{}{}
}
func (tv *logTagValue) seriesIDs() []uint64 {

View File

@ -470,7 +470,7 @@ func (i *Partition) DropMeasurement(name []byte) error {
if err := func() error {
i.mu.RLock()
defer i.mu.RUnlock()
return i.activeLogFile.DeleteSeriesID(s.SeriesID)
return i.sfile.DeleteSeriesID(s.SeriesID)
}(); err != nil {
return err
}
@ -529,7 +529,7 @@ func (i *Partition) DropSeries(key []byte) error {
mname := []byte(name)
seriesID := i.sfile.Offset(mname, tags, nil)
if err := i.activeLogFile.DeleteSeriesID(seriesID); err != nil {
if err := i.sfile.DeleteSeriesID(seriesID); err != nil {
return err
}

View File

@ -50,6 +50,7 @@ type SeriesFile struct {
seriesMap *seriesMap
compactingSeriesMap *seriesMap
tombstones map[uint64]struct{}
// MaxSize is the maximum size of the file.
MaxSize int64
@ -59,6 +60,7 @@ type SeriesFile struct {
func NewSeriesFile(path string) *SeriesFile {
return &SeriesFile{
path: path,
tombstones: make(map[uint64]struct{}),
MaxSize: DefaultMaxSeriesFileSize,
}
}
@ -227,6 +229,13 @@ func (f *SeriesFile) CreateSeriesListIfNotExists(names [][]byte, tagsSlice []mod
return offsets, nil
}
// DeleteSeries flags a series as permanently deleted.
// If the series is reintroduced later then it must create a new offset.
func (f *SeriesFile) DeleteSeries(offset uint64) error {
f.tombstones[offset] = struct{}{}
return nil
}
// Offset returns the byte offset of the series within the block.
func (f *SeriesFile) Offset(name []byte, tags models.Tags, buf []byte) (offset uint64) {
f.mu.RLock()
@ -236,7 +245,13 @@ func (f *SeriesFile) Offset(name []byte, tags models.Tags, buf []byte) (offset u
}
func (f *SeriesFile) offset(name []byte, tags models.Tags, buf []byte) uint64 {
return f.seriesMap.offset(AppendSeriesKey(buf[:0], name, tags))
offset := f.seriesMap.offset(AppendSeriesKey(buf[:0], name, tags))
if offset == 0 {
return 0
} else if _, ok := f.tombstones[offset]; ok {
return 0
}
return offset
}
// SeriesKey returns the series key for a given offset.