Repository: dolthub/dolt
File: go/store/nbs/journal.go (Go)

Code before:
			return chunks.ErrGCGenerationExpired
		}
		return nil
	}
	return updateWithChecker(ctx, jm.dir, syncFlush, checker, lastLock, newContents, writeHook)
}

// UpdateGCGen implements manifest.
func (jm *journalManifest) UpdateGCGen(ctx context.Context, lastLock hash.Hash, newContents manifestContents, stats *Stats, writeHook func() error) (mc manifestContents, err error) {
	if jm.readOnly() {
		_, mc, err = jm.ParseIfExists(ctx, stats, nil)
		if err != nil {
			return manifestContents{}, err
		}
		// return current contents and sentinel error
		return mc, errReadOnlyManifest
	}

	t1 := time.Now()
	defer func() { stats.WriteManifestLatency.SampleTimeSince(t1) }()
	return updateWithChecker(ctx, jm.dir, syncFlush, updateGCGenManifestCheck, lastLock, newContents, writeHook)
}

func updateGCGenManifestCheck(upstream, contents manifestContents) error {
	if contents.root != upstream.root {
		return errors.New("UpdateGCGen() cannot update the root")
	} else if contents.gcGen == upstream.gcGen {
		// Allow a no-op update.  These can happen
		// when we went through a GC cycle because the
		// store had novelty (novel upstreams,
		// memtables), but the end state was still the
		// same as what was in the manifest.
		return nil
	}
	return nil
}

func (jm *journalManifest) Close() (err error) {
	if jm.lock != nil {
		err = jm.lock.Unlock()
		jm.lock = nil
	}
	return
}

func containsJournalSpec(specs []tableSpec) (ok bool) {
	for _, spec := range specs {
		if spec.name == journalAddr {
			ok = true
			break
		}

Review comment (bug):
Is this always an indication of a bug, or is it sometimes expected? If the former, language encouraging the user to report it would be a good idea.

Code after:
			return chunks.ErrGCGenerationExpired
		}
		return nil
	}
	return updateWithChecker(ctx, jm.dir, syncFlush, checker, lastLock, newContents, writeHook)
}

// UpdateGCGen implements manifest.
func (jm *journalManifest) UpdateGCGen(ctx context.Context, lastLock hash.Hash, newContents manifestContents, stats *Stats, writeHook func() error) (mc manifestContents, err error) {
	if jm.readOnly() {
		_, mc, err = jm.ParseIfExists(ctx, stats, nil)
		if err != nil {
			return manifestContents{}, err
		}
		// return current contents and sentinel error
		return mc, errReadOnlyManifest
	}

	t1 := time.Now()
	defer func() { stats.WriteManifestLatency.SampleTimeSince(t1) }()
	return updateWithChecker(ctx, jm.dir, syncFlush, updateGCGenManifestCheck, lastLock, newContents, writeHook)
}

func updateGCGenManifestCheck(upstream, contents manifestContents) error {
	if contents.root != upstream.root {
		return errors.New("UpdateGCGen() cannot update the root. The attempt to do this is a bug in Dolt. Please report at https://github.com/dolthub/dolt/issues.")
	} else if contents.gcGen == upstream.gcGen {
		// Allow a no-op update.  These can happen
		// when we went through a GC cycle because the
		// store had novelty (novel upstreams,
		// memtables), but the end state was still the
		// same as what was in the manifest.
		return nil
	}
	return nil
}

func (jm *journalManifest) Close() (err error) {
	if jm.lock != nil {
		err = jm.lock.Unlock()
		jm.lock = nil
	}
	return
}

func containsJournalSpec(specs []tableSpec) (ok bool) {
	for _, spec := range specs {
		if spec.name == journalAddr {
			ok = true
			break
		}