-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Implement chunk support for collector (#270)
Implement chunk support for collector. The garbage collector now deletes any ChunkRef and the underlying objects even when the parent BlobRef remains active.
- Loading branch information
Showing
7 changed files
with
375 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// Copyright 2021 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package chunkref | ||
|
||
import ( | ||
ds "cloud.google.com/go/datastore" | ||
"github.com/googleforgames/open-saves/internal/pkg/metadb/blobref" | ||
) | ||
|
||
var ( | ||
ErrIteratorNil = blobref.ErrIteratorNil | ||
) | ||
|
||
// ChunkRefCursor is a database cursor for ChunkRef. | ||
type ChunkRefCursor struct { | ||
iter *ds.Iterator | ||
} | ||
|
||
func NewCursor(i *ds.Iterator) *ChunkRefCursor { | ||
return &ChunkRefCursor{iter: i} | ||
} | ||
|
||
// Next advances the iterator and returns the next value. | ||
// Returns nil and and iterator.Done at the end of the iterator. | ||
// Returns ErrIteratorNil if the iterator is nil. | ||
func (i *ChunkRefCursor) Next() (*ChunkRef, error) { | ||
if i == nil { | ||
return nil, ErrIteratorNil | ||
} | ||
if i.iter == nil { | ||
return nil, ErrIteratorNil | ||
} | ||
var chunk ChunkRef | ||
_, err := i.iter.Next(&chunk) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return &chunk, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Copyright 2021 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package chunkref | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestCursor_NextOnNil(t *testing.T) { | ||
c := NewCursor(nil) | ||
b, err := c.Next() | ||
assert.Nil(t, b) | ||
assert.ErrorIs(t, ErrIteratorNil, err) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.