Docs Menu
Docs Home
/
MongoDB ๋งค๋‰ด์–ผ
/ / /

$changeStreamSplitLargeEvent (์ง‘๊ณ„)

์ด ํŽ˜์ด์ง€์˜ ๋‚ด์šฉ

  • ์ •์˜
  • ํ–‰๋™
  • ์˜ˆ์‹œ
$changeStreamSplitLargeEvent

MongoDB 7.0(๋ฐ 6.0.9)์˜ ์ƒˆ๋กœ์šด ๊ธฐ๋Šฅ

๋ณ€๊ฒฝ ์ŠคํŠธ๋ฆผ ์— 16 MB๋ฅผ ์ดˆ๊ณผํ•˜๋Š” ๋Œ€๊ทœ๋ชจ ์ด๋ฒคํŠธ๊ฐ€ ์žˆ๋Š” ๊ฒฝ์šฐ BSONObjectTooLarge ์˜ˆ์™ธ๊ฐ€ ๋ฐ˜ํ™˜๋ฉ๋‹ˆ๋‹ค. MongoDB 7.0 (๋ฐ 6.0.9)๋ถ€ํ„ฐ๋Š” $changeStreamSplitLargeEvent ๋‹จ๊ณ„๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์ด๋ฒคํŠธ๋ฅผ ๋” ์ž‘์€ ์กฐ๊ฐ์œผ๋กœ ๋ถ„ํ•  ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

๊ผญ ํ•„์š”ํ•œ ๊ฒฝ์šฐ์—๋งŒ $changeStreamSplitLargeEvent๋ฅผ ์‚ฌ์šฉํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด, ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์— ์ „์ฒด ๋ฌธ์„œ ์‚ฌ์ „ ๋˜๋Š” ์‚ฌํ›„ ์ด๋ฏธ์ง€๊ฐ€ ํ•„์š”ํ•˜๊ณ  16MB๋ฅผ ์ดˆ๊ณผํ•˜๋Š” ํฐ ์ด๋ฒคํŠธ๋ฅผ ์ƒ์„ฑํ•˜๋Š” ๊ฒฝ์šฐ, $changeStreamSplitLargeEvent๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

$changeStreamSplitLargeEvent ์‚ฌ์šฉํ•˜๊ธฐ๋กœ ๊ฒฐ์ •ํ•˜๊ธฐ ์ „์— ๋จผ์ € ๋ณ€๊ฒฝ ์ด๋ฒคํŠธ ํฌ๊ธฐ๋ฅผ ์ค„์—ฌ์•ผ ํ•ฉ๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ์˜ˆ์‹œ ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค.

  • ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์— ์‚ฌ์ „ ๋˜๋Š” ์‚ฌํ›„ ์ด๋ฏธ์ง€๊ฐ€ ํ•„์š”ํ•˜์ง€ ์•Š๋Š” ํ•œ ๋ฌธ์„œ ์‚ฌ์ „ ๋˜๋Š” ์‚ฌํ›„ ์ด๋ฏธ์ง€๋ฅผ ์š”์ฒญํ•˜์ง€ ๋งˆ์„ธ์š”. ์ด๋ ‡๊ฒŒ ํ•˜๋ฉด fullDocument ๋ฐ fullDocumentBeforeChange ํ•„๋“œ๊ฐ€ ๋” ๋งŽ์ด ์ƒ์„ฑ๋˜๋ฉฐ, ์ด๋Š” ์ผ๋ฐ˜์ ์œผ๋กœ ๋ณ€๊ฒฝ ์ด๋ฒคํŠธ์—์„œ ๊ฐ€์žฅ ํฐ ๊ฐ์ฒด์ž…๋‹ˆ๋‹ค.

  • ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์— ํ•„์š”ํ•œ ํ•„๋“œ๋งŒ ํฌํ•จํ•˜๋ ค๋ฉด $project ๋‹จ๊ณ„๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. ์ด๋ ‡๊ฒŒ ํ•˜๋ฉด ๋ณ€๊ฒฝ ์ด๋ฒคํŠธ ํฌ๊ธฐ๊ฐ€ ์ค„์–ด๋“ค๊ณ  ํฐ ์ด๋ฒคํŠธ๋ฅผ ์—ฌ๋Ÿฌ ์กฐ๊ฐ์œผ๋กœ ๋ถ„ํ• ํ•˜๋Š” ๋ฐ ์ถ”๊ฐ€ ์‹œ๊ฐ„์ด ๊ฑธ๋ฆฌ์ง€ ์•Š์Šต๋‹ˆ๋‹ค. ์ด๋ ‡๊ฒŒ ํ•˜๋ฉด ๊ฐ ๋ฐฐ์น˜์—์„œ ๋” ๋งŽ์€ ๋ณ€๊ฒฝ ์ด๋ฒคํŠธ๋ฅผ ๋ฐ˜ํ™˜ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

ํŒŒ์ดํ”„๋ผ์ธ์—๋Š” $changeStreamSplitLargeEvent ๋‹จ๊ณ„๋ฅผ ํ•˜๋‚˜๋งŒ ๊ฐ€์งˆ ์ˆ˜ ์žˆ์œผ๋ฉฐ, ์ด ๋‹จ๊ณ„๋Š” ๋ฐ˜๋“œ์‹œ ๋งˆ์ง€๋ง‰ ๋‹จ๊ณ„์—ฌ์•ผ ํ•ฉ๋‹ˆ๋‹ค. $changeStream ํŒŒ์ดํ”„๋ผ์ธ์—์„œ๋Š” $changeStreamSplitLargeEvent๋งŒ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

$changeStreamSplitLargeEvent ๊ตฌ๋ฌธ:

{
$changeStreamSplitLargeEvent: {}
}

$changeStreamSplitLargeEvent 16 MB๋ฅผ ์ดˆ๊ณผํ•˜๋Š” ์ด๋ฒคํŠธ๋ฅผ ํ”„๋ž˜๊ทธ๋จผํŠธ๋กœ ๋ถ„ํ• ํ•˜๊ณ  ๋ณ€๊ฒฝ ์ŠคํŠธ๋ฆผ ์ปค์„œ ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ํ”„๋ž˜๊ทธ๋จผํŠธ๋ฅผ ์ˆœ์ฐจ์ ์œผ๋กœ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.

ํ”„๋ž˜๊ทธ๋จผํŠธ๋Š” ์ฒซ ๋ฒˆ์งธ ํ”„๋ž˜๊ทธ๋จผํŠธ์—์„œ ์ตœ๋Œ€ ๊ฐœ์ˆ˜์˜ ํ•„๋“œ๊ฐ€ ๋ฐ˜ํ™˜๋˜๋„๋ก ๋ถ„ํ•  ๋ฉ๋‹ˆ๋‹ค. ์ด๋ ‡๊ฒŒ ํ•˜๋ฉด ์ด๋ฒคํŠธ ์ปจํ…์ŠคํŠธ๊ฐ€ ๊ฐ€๋Šฅํ•œ ํ•œ ๋นจ๋ฆฌ ๋ฐ˜ํ™˜๋ฉ๋‹ˆ๋‹ค.

๋ณ€๊ฒฝ ์ด๋ฒคํŠธ๊ฐ€ ๋ถ„ํ• ๋˜๋ฉด ์ตœ์ƒ์œ„ ํ•„๋“œ ํฌ๊ธฐ๋งŒ ์‚ฌ์šฉ๋ฉ๋‹ˆ๋‹ค. $changeStreamSplitLargeEvent๋Š” ํ•˜์œ„ ๋ฌธ์„œ๋ฅผ ๋ฐ˜๋ณต์ ์œผ๋กœ ์ฒ˜๋ฆฌํ•˜๊ฑฐ๋‚˜ ๋ถ„ํ• ํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด $project ๋‹จ๊ณ„๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ํฌ๊ธฐ๊ฐ€ 20 MB์ธ ๋‹จ์ผ ํ•„๋“œ๊ฐ€ ์žˆ๋Š” ๋ณ€๊ฒฝ ์ด๋ฒคํŠธ๋ฅผ ์ƒ์„ฑํ•˜๋Š” ๊ฒฝ์šฐ ์ด๋ฒคํŠธ๊ฐ€ ๋ถ„ํ• ๋˜์ง€ ์•Š๊ณ  ๋‹จ๊ณ„์—์„œ ์˜ค๋ฅ˜๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.

๊ฐ ์กฐ๊ฐ์—๋Š” ์žฌ๊ฐœ ํ† ํฐ์ด ์žˆ์Šต๋‹ˆ๋‹ค. ์กฐ๊ฐ์˜ ํ† ํฐ์„ ์‚ฌ์šฉํ•˜์—ฌ ์ŠคํŠธ๋ฆผ์ด ์žฌ๊ฐœ๋˜๋ฉด ๋‹ค์Œ ์ค‘ ํ•˜๋‚˜๋ฅผ ์ˆ˜ํ–‰ํ•ฉ๋‹ˆ๋‹ค.

  • ํ›„์† ํ”„๋ž˜๊ทธ๋จผํŠธ์—์„œ ์ƒˆ ์ŠคํŠธ๋ฆผ ์„ ์‹œ์ž‘ํ•ฉ๋‹ˆ๋‹ค.

  • ์‹œํ€€์Šค์˜ ๋งˆ์ง€๋ง‰ ์กฐ๊ฐ์—์„œ ์žฌ๊ฐœํ•˜๋Š” ๊ฒฝ์šฐ ๋‹ค์Œ ์ด๋ฒคํŠธ๋ถ€ํ„ฐ ์‹œ์ž‘ํ•ฉ๋‹ˆ๋‹ค.

์ด๋ฒคํŠธ ์˜ ๊ฐ ํ”„๋ž˜๊ทธ๋จผํŠธ์—๋Š” splitEvent ๋ฌธ์„œ ๊ฐ€ ํฌํ•จ๋ฉ๋‹ˆ๋‹ค.

splitEvent: {
fragment: <int>,
of: <int>
}

๋‹ค์Œ ํ‘œ์—์„œ๋Š” ํ•„๋“œ์— ๋Œ€ํ•ด ์„ค๋ช…ํ•ฉ๋‹ˆ๋‹ค.

ํ•„๋“œ
์„ค๋ช…

fragment

1 ์—์„œ ์‹œ์ž‘ํ•˜๋Š” ํ”„๋ž˜๊ทธ๋จผํŠธ ์ธ๋ฑ์Šค ์ž…๋‹ˆ๋‹ค.

of

์ด๋ฒคํŠธ์— ๋Œ€ํ•œ ์ด ์กฐ๊ฐ ์ˆ˜์ž…๋‹ˆ๋‹ค.

์ด ์„น์…˜์˜ ์˜ˆ์‹œ ์‹œ๋‚˜๋ฆฌ์˜ค์—์„œ๋Š” myCollection ์ด๋ผ๋Š” ์ƒˆ ์ปฌ๋ ‰์…˜ ๊ณผ ํ•จ๊ป˜ $changeStreamSplitLargeEvent ์„ ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ๋ณด์—ฌ ์ค๋‹ˆ๋‹ค.

myCollection ์„ ๋งŒ๋“ค๊ณ  ๋ฐ์ดํ„ฐ๊ฐ€ 16 MB ๋ฏธ๋งŒ์ธ ๋ฌธ์„œ ํ•˜๋‚˜๋ฅผ ์‚ฝ์ž…ํ•ฉ๋‹ˆ๋‹ค.

db.myCollection.insertOne(
{ _id: 0, largeField: "a".repeat( 16 * 1024 * 1024 - 1024 ) }
)

largeField ๋ฐ˜๋ณต๋˜๋Š” ๋ฌธ์ž a ์„ ํฌํ•จํ•ฉ๋‹ˆ๋‹ค.

myCollection์— changeStreamPreAndPostImages๋ฅผ ํ™œ์„ฑํ™”ํ•˜๋ฉด ๋ณ€๊ฒฝ ์ŠคํŠธ๋ฆผ์ด ์—…๋ฐ์ดํŠธ ์ „(์‚ฌ์ „ ์ด๋ฏธ์ง€)๊ณผ ์—…๋ฐ์ดํŠธ ํ›„(์‚ฌํ›„ ์ด๋ฏธ์ง€)์˜ ๋ฌธ์„œ๋ฅผ ๊ฒ€์ƒ‰ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

db.runCommand( {
collMod: "myCollection",
changeStreamPreAndPostImages: { enabled: true }
} )

๋ณ€๊ฒฝ ์ŠคํŠธ๋ฆผ ์ปค์„œ ๋ฅผ ์ƒ์„ฑํ•˜์—ฌ db.collection.watch()์„ ์‚ฌ์šฉํ•˜์—ฌ myCollection ์— ๋Œ€ํ•œ ๋ณ€๊ฒฝ ์‚ฌํ•ญ์„ ๋ชจ๋‹ˆํ„ฐ ํ•ฉ๋‹ˆ๋‹ค.

myChangeStreamCursor = db.myCollection.watch(
[ { $changeStreamSplitLargeEvent: {} } ],
{ fullDocument: "required", fullDocumentBeforeChange: "required" }
)

๋ณ€๊ฒฝ ์ŠคํŠธ๋ฆผ ์ด๋ฒคํŠธ์˜ ๊ฒฝ์šฐ:

  • fullDocument: "required" ๋ฌธ์„œ ํฌ์ŠคํŠธ ์ด๋ฏธ์ง€๊ฐ€ ํฌํ•จ๋ฉ๋‹ˆ๋‹ค.

  • fullDocumentBeforeChange: "required" ๋Š” ๋ฌธ์„œ ์‚ฌ์ „ ์ด๋ฏธ์ง€๋ฅผ ํฌํ•จํ•ฉ๋‹ˆ๋‹ค.

์ž์„ธํ•œ ๋‚ด์šฉ์€ $changeStream๋ฅผ ์ฐธ์กฐํ•˜์„ธ์š”.

myCollection ์—์„œ ๋ฌธ์„œ ๋ฅผ ์—…๋ฐ์ดํŠธํ•˜๋ฉด ๋ฌธ์„œ ์‚ฌ์ „ ๋ฐ ์‚ฌํ›„ ์ด๋ฏธ์ง€๋กœ ๋ณ€๊ฒฝ ์ŠคํŠธ๋ฆผ ์ด๋ฒคํŠธ ๋„ ์ƒ์„ฑ๋ฉ๋‹ˆ๋‹ค.

db.myCollection.updateOne(
{ _id: 0 },
{ $set: { largeField: "b".repeat( 16 * 1024 * 1024 - 1024 ) } }
)

largeField ์ด์ œ ๋ฐ˜๋ณต๋˜๋Š” ๋ฌธ์ž b ์„ ํฌํ•จํ•ฉ๋‹ˆ๋‹ค.

next() ๋ฉ”์„œ๋“œ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ myChangeStreamCursor์—์„œ ์กฐ๊ฐ์„ ๊ฒ€์ƒ‰ํ•˜๊ณ  firstFragment, secondFragment ๋ฐ thirdFragment๋ผ๋Š” ๊ฐ์ฒด์— ์กฐ๊ฐ์„ ์ €์žฅํ•ฉ๋‹ˆ๋‹ค.

const firstFragment = myChangeStreamCursor.next()
const secondFragment = myChangeStreamCursor.next()
const thirdFragment = myChangeStreamCursor.next()

firstFragment.splitEvent ํ‘œ์‹œ:

firstFragment.splitEvent

ํ”„๋ž˜๊ทธ๋จผํŠธ ์„ธ๋ถ€ ์ •๋ณด๊ฐ€ ํฌํ•จ๋œ ์ถœ๋ ฅ:

splitEvent: { fragment: 1, of: 3 }

๋งˆ์ฐฌ๊ฐ€์ง€๋กœ secondFragment.splitEvent ๋ฐ thirdFragment.splitEvent ๋Š” ๋‹ค์Œ์„ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.

splitEvent: { fragment: 2, of: 3 }
splitEvent: { fragment: 3, of: 3 }

firstFragment ์— ๋Œ€ํ•œ ๊ฐ์ฒด ํ‚ค๋ฅผ ๊ฒ€์‚ฌํ•˜๋ ค๋ฉด ๋‹ค์Œ์„ ์ˆ˜ํ–‰ํ•ฉ๋‹ˆ๋‹ค.

Object.keys( firstFragment )

์ถœ๋ ฅ:

[
'_id',
'splitEvent',
'wallTime',
'clusterTime',
'operationType',
'documentKey',
'ns',
'fullDocument'
]

firstFragment.fullDocument ์˜ ํฌ๊ธฐ๋ฅผ ๋ฐ”์ดํŠธ ๋‹จ์œ„๋กœ ๊ฒ€์‚ฌํ•˜๋ ค๋ฉด ๋‹ค์Œ์„ ์ˆ˜ํ–‰ํ•ฉ๋‹ˆ๋‹ค.

bsonsize( firstFragment.fullDocument )

์ถœ๋ ฅ:

16776223

secondFragment ์—๋Š” ํฌ๊ธฐ๊ฐ€ ์•ฝ 16MB์ธ fullDocumentBeforeChange ์‚ฌ์ „ ์ด๋ฏธ์ง€๊ฐ€ ํฌํ•จ๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค. ๋‹ค์Œ ์˜ˆ๋Š” secondFragment ์— ๋Œ€ํ•œ ๊ฐ์ฒด ํ‚ค๋ฅผ ๋ณด์—ฌ์ค๋‹ˆ๋‹ค.

Object.keys( secondFragment )

์ถœ๋ ฅ:

[ '_id', 'splitEvent', 'fullDocumentBeforeChange' ]

thirdFragment ์•ฝ 16MB ํฌ๊ธฐ์˜ updateDescription ํ•„๋“œ๋ฅผ ํฌํ•จํ•ฉ๋‹ˆ๋‹ค. ๋‹ค์Œ ์˜ˆ๋Š” thirdFragment ์— ๋Œ€ํ•œ ๊ฐ์ฒด ํ‚ค๋ฅผ ๋ณด์—ฌ์ค๋‹ˆ๋‹ค.

Object.keys( thirdFragment )

์ถœ๋ ฅ:

[ '_id', 'splitEvent', 'updateDescription' ]

change stream ๋ฐ ์ด๋ฒคํŠธ์— ๋Œ€ํ•œ ์ž์„ธํ•œ ๋‚ด์šฉ์€ ๋ณ€๊ฒฝ ์ด๋ฒคํŠธ๋ฅผ ์ฐธ์กฐํ•˜์„ธ์š”.

๋Œ์•„๊ฐ€๊ธฐ

$changeStream

์ด ํŽ˜์ด์ง€์˜ ๋‚ด์šฉ