Skip to content

Commit

Permalink
Move ContentPrefix const to content pkg
Browse files Browse the repository at this point in the history
Signed-off-by: Prasad Ghangal <[email protected]>
  • Loading branch information
PrasadG193 committed Jul 23, 2024
1 parent b29e3a5 commit 6f98674
Show file tree
Hide file tree
Showing 9 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion internal/server/grpc_session.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ func handleWriteContentRequest(ctx context.Context, dw repo.DirectRepositoryWrit
return accessDeniedResponse()
}

if strings.HasPrefix(req.GetPrefix(), manifest.ContentPrefix) {
if strings.HasPrefix(req.GetPrefix(), content.ManifestContentPrefix) {
// it's not allowed to create contents prefixed with 'm' since those could be mistaken for manifest contents.
return accessDeniedResponse()
}
Expand Down
2 changes: 1 addition & 1 deletion internal/server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ func remoteRepositoryTest(ctx context.Context, t *testing.T, rep repo.Repository
mustReadObject(ctx, t, w, result, written)

ow := w.NewObjectWriter(ctx, object.WriterOptions{
Prefix: manifest.ContentPrefix,
Prefix: content.ManifestContentPrefix,
})

_, err := ow.Write([]byte{2, 3, 4})
Expand Down
5 changes: 5 additions & 0 deletions repo/content/content_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ const (
DefaultIndexVersion = 2
)

// ManifestContentPrefix is the prefix of the content id for manifests.
const (
ManifestContentPrefix = "m"
)

var tracer = otel.Tracer("kopia/content")

// PackBlobIDPrefixes contains all possible prefixes for pack blobs.
Expand Down
2 changes: 1 addition & 1 deletion repo/content/content_manager_lock_free.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func (sm *SharedManager) maybeCompressAndEncryptDataForPacking(data gather.Bytes
// and we're on V2 format or greater, enable internal compression even when not requested.
// Set compression only for manifest metadata.
// TODO: Remove this check once metadata compression setting is implemented for manifest metadata.
if contentID.HasPrefix() && contentID.Prefix() == "m" && comp == NoCompression && mp.IndexVersion >= index.Version2 {
if contentID.HasPrefix() && contentID.Prefix() == ManifestContentPrefix && comp == NoCompression && mp.IndexVersion >= index.Version2 {
// 'zstd-fastest' has a good mix of being fast, low memory usage and high compression for JSON.
comp = compression.HeaderZstdFastest
}
Expand Down
2 changes: 1 addition & 1 deletion repo/grpc_repository_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -721,7 +721,7 @@ func (r *grpcRepositoryClient) WriteContent(ctx context.Context, data gather.Byt
}

// we will be writing asynchronously and server will reject this write, fail early.
if prefix == manifest.ContentPrefix {
if prefix == content.ManifestContentPrefix {
return content.EmptyID, errors.Errorf("writing manifest contents not allowed")
}

Expand Down
4 changes: 2 additions & 2 deletions repo/manifest/committed_manifest_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func (m *committedManifestManager) writeEntriesLocked(ctx context.Context, entri
mustSucceed(gz.Flush())
mustSucceed(gz.Close())

contentID, err := m.b.WriteContent(ctx, buf.Bytes(), ContentPrefix, content.NoCompression)
contentID, err := m.b.WriteContent(ctx, buf.Bytes(), content.ManifestContentPrefix, content.NoCompression)
if err != nil {
return nil, errors.Wrap(err, "unable to write content")
}
Expand Down Expand Up @@ -145,7 +145,7 @@ func (m *committedManifestManager) loadCommittedContentsLocked(ctx context.Conte
manifests = map[content.ID]manifest{}

err := m.b.IterateContents(ctx, content.IterateOptions{
Range: index.PrefixRange(ContentPrefix),
Range: index.PrefixRange(content.ManifestContentPrefix),
Parallel: manifestLoadParallelism,
}, func(ci content.Info) error {
man, err := loadManifestContent(ctx, m.b, ci.ContentID)
Expand Down
8 changes: 2 additions & 6 deletions repo/manifest/manifest_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,15 @@ import (
const (
manifestLoadParallelism = 8
manifestIDLength = 16

autoCompactionContentCountDefault = 16
)

var log = logging.Module("kopia/manifest") // +checklocksignore

// ErrNotFound is returned when the metadata item is not found.
var ErrNotFound = errors.New("not found")

// ContentPrefix is the prefix of the content id for manifests.
const (
ContentPrefix = "m"
autoCompactionContentCountDefault = 16
)

// TypeLabelKey is the label key for manifest type.
const TypeLabelKey = "type"

Expand Down
4 changes: 2 additions & 2 deletions repo/manifest/manifest_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func TestManifest(t *testing.T) {

if err := mgr.b.IterateContents(
ctx,
content.IterateOptions{Range: index.PrefixRange(ContentPrefix)},
content.IterateOptions{Range: index.PrefixRange(content.ManifestContentPrefix)},
func(ci content.Info) error {
foundContents++
return nil
Expand Down Expand Up @@ -447,7 +447,7 @@ func getManifestContentCount(ctx context.Context, t *testing.T, mgr *Manager) in

if err := mgr.b.IterateContents(
ctx,
content.IterateOptions{Range: index.PrefixRange(ContentPrefix)},
content.IterateOptions{Range: index.PrefixRange(content.ManifestContentPrefix)},
func(ci content.Info) error {
foundContents++
return nil
Expand Down
3 changes: 1 addition & 2 deletions snapshot/snapshotgc/gc.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"github.com/kopia/kopia/repo/content"
"github.com/kopia/kopia/repo/logging"
"github.com/kopia/kopia/repo/maintenance"
"github.com/kopia/kopia/repo/manifest"
"github.com/kopia/kopia/repo/object"
"github.com/kopia/kopia/snapshot"
"github.com/kopia/kopia/snapshot/snapshotfs"
Expand Down Expand Up @@ -116,7 +115,7 @@ func runInternal(ctx context.Context, rep repo.DirectRepositoryWriter, gcDelete
// Ensure that the iteration includes deleted contents, so those can be
// undeleted (recovered).
err := rep.ContentReader().IterateContents(ctx, content.IterateOptions{IncludeDeleted: true}, func(ci content.Info) error {
if manifest.ContentPrefix == ci.ContentID.Prefix() {
if content.ManifestContentPrefix == ci.ContentID.Prefix() {
system.Add(int64(ci.PackedLength))
return nil
}
Expand Down

0 comments on commit 6f98674

Please sign in to comment.