Skip to content

Commit

Permalink
Fixed Typo
Browse files Browse the repository at this point in the history
  • Loading branch information
jiwon.yum committed Nov 24, 2024
1 parent d84d31d commit e99ab4c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 14 deletions.
13 changes: 3 additions & 10 deletions server/backend/database/mongo/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -1070,56 +1070,49 @@ func (c *Client) CreateSnapshotInfo(
docRefKey types.DocRefKey,
doc *document.InternalDocument,
) error {
// 스냅샷 생성
snapshot, err := converter.SnapshotToBytes(doc.RootObject(), doc.AllPresences())
if err != nil {
return err
}

// 16MB 이상이면 GridFS에 저장
const maxSnapshotSize = 16 * 1024 * 1024 // 16MB
if len(snapshot) > maxSnapshotSize {
log.Println("16MB over!!!")

db := c.client.Database(c.config.YorkieDatabase)

// GridFS 버킷 생성
bucket, err := gridfs.NewBucket(db) // MongoDB의 c.db는 데이터베이스 객체
// create GridFS bucket
bucket, err := gridfs.NewBucket(db)
if err != nil {
return fmt.Errorf("failed to create GridFS bucket: %w", err)
}

// GridFS에 파일 업로드
uploadStream, err := bucket.OpenUploadStream(fmt.Sprintf("%s_snapshot", docRefKey.DocID))
if err != nil {
return fmt.Errorf("failed to open GridFS upload stream: %w", err)
}
defer uploadStream.Close()

Check failure on line 1094 in server/backend/database/mongo/client.go

View workflow job for this annotation

GitHub Actions / build

Error return value of `uploadStream.Close` is not checked (errcheck)

// 스냅샷 데이터를 GridFS에 저장
_, err = uploadStream.Write(snapshot)
if err != nil {
return fmt.Errorf("failed to write to GridFS: %w", err)
}

// 파일의 ID (GridFS에서 파일을 식별하는 ObjectId)
fileID := uploadStream.FileID

// GridFS에 저장된 파일 ID를 사용하여 문서 삽입
if _, err := c.collection(ColSnapshots).InsertOne(ctx, bson.M{
"project_id": docRefKey.ProjectID,
"doc_id": docRefKey.DocID,
"server_seq": doc.Checkpoint().ServerSeq,
"lamport": doc.Lamport(),
"version_vector": doc.VersionVector(),
"snapshot_file_id": fileID, // GridFS 파일 ID
"snapshot_file_id": fileID, // GridFS file ID
"created_at": gotime.Now(),
}); err != nil {
return fmt.Errorf("insert snapshot info: %w", err)
}

} else {
// 스냅샷이 16MB 이하일 경우 일반적인 컬렉션에 삽입
if _, err := c.collection(ColSnapshots).InsertOne(ctx, bson.M{
"project_id": docRefKey.ProjectID,
"doc_id": docRefKey.DocID,
Expand Down
7 changes: 3 additions & 4 deletions server/backend/database/testcases/testcases.go
Original file line number Diff line number Diff line change
Expand Up @@ -1620,7 +1620,7 @@ func AssertKeys(t *testing.T, expectedKeys []key.Key, infos []*database.DocInfo)
assert.EqualValues(t, expectedKeys, keys)
}

func CreateLargeSnapshotTest(t *testing.T, db database.Database, projectID types.ID) {
func RunCreateLargeSnapshotTest(t *testing.T, db database.Database, projectID types.ID) {

Check failure on line 1623 in server/backend/database/testcases/testcases.go

View workflow job for this annotation

GitHub Actions / build

exported: exported function RunCreateLargeSnapshotTest should have comment or be unexported (revive)
t.Run("store and validate large snapshot test", func(t *testing.T) {
ctx := context.Background()
docKey := key.Key(fmt.Sprintf("tests$%s", t.Name()))
Expand All @@ -1633,9 +1633,9 @@ func CreateLargeSnapshotTest(t *testing.T, db database.Database, projectID types
doc := document.New(docKey)
doc.SetActor(actorID)

largeData := make([]byte, 16*1024*1024+1) // 16MB + 1 byte
largeData := make([]byte, 16*1024*1024+1)
for i := range largeData {
largeData[i] = byte('A' + (i % 26)) // A-Z 반복
largeData[i] = byte('A' + (i % 26))
}

assert.NoError(t, doc.Update(func(root *json.Object, p *presence.Presence) error {
Expand All @@ -1645,7 +1645,6 @@ func CreateLargeSnapshotTest(t *testing.T, db database.Database, projectID types

docRefKey := docInfo.RefKey()

// 스냅샷 생성 및 오류 확인
err := db.CreateSnapshotInfo(ctx, docRefKey, doc.InternalDocument())
assert.NoError(t, err)
})
Expand Down

0 comments on commit e99ab4c

Please sign in to comment.