From b038afa0499c40f9f9bb463cf2c7f7acc2571add Mon Sep 17 00:00:00 2001 From: Philip O'Toole Date: Fri, 8 May 2015 11:49:52 -0700 Subject: [PATCH] Don't truncate topic data unless fully replicated Fix issue #2521 --- CHANGELOG.md | 7 +++++++ messaging/broker.go | 20 ++++++++++++-------- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d3b47113255..e183026e0b2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +## v0.9.0-rc30 [unreleased] + +### Features + +### Bugfixes +- [#2521](https://github.com/influxdb/influxdb/pull/2521): Don't truncate topic data until fully replicated. + ## v0.9.0-rc29 [2015-05-05] ### Features diff --git a/messaging/broker.go b/messaging/broker.go index 61ffa837b64..ae3cec0fc00 100644 --- a/messaging/broker.go +++ b/messaging/broker.go @@ -8,6 +8,7 @@ import ( "hash/fnv" "io" "log" + "math" "net/url" "os" "path/filepath" @@ -950,12 +951,15 @@ func (t *Topic) Truncate(maxSize int64) (int, int64, error) { return 0, 0, err } - // Find the highest-replicated index, this is a condition for deletion of segments - // within this topic. - var highestIndex uint64 - for _, idx := range t.indexByURL { - if idx > highestIndex { - highestIndex = idx + // Find the index that has been fully replicated, this is a condition for deletion of + // segments within this topic. + var replicatedIndex uint64 + if len(t.indexByURL) > 0 { + replicatedIndex = math.MaxUint64 + for _, idx := range t.indexByURL { + if idx < replicatedIndex { + replicatedIndex = idx + } } } @@ -978,8 +982,8 @@ func (t *Topic) Truncate(maxSize int64) (int, int64, error) { // The first segment can only be deleted if the last index in that segment has // been replicated. The most efficient way to check this is to ensure that the // first index of the subsequent segment has been replicated. - if second.Index > highestIndex { - // No guarantee first segment has been replicated. + if second.Index > replicatedIndex { + // First segment has not been fully replicated. break }