@@ -118,6 +118,7 @@ func (cb *fileBlockReader) getChangedBlockMetadata(ctx context.Context) ([]*csi.
118118 blockIndex := cb .offset / cb .blockSize
119119 sBuffer := make ([]byte , cb .blockSize )
120120 tBuffer := make ([]byte , cb .blockSize )
121+ zeroBlock := make ([]byte , cb .blockSize )
121122 eofBaseFile , eofTargetFile := false , false
122123
123124 changedBlocks := []* csi.BlockMetadata {}
@@ -143,15 +144,19 @@ func (cb *fileBlockReader) getChangedBlockMetadata(ctx context.Context) ([]*csi.
143144 if eofTargetFile {
144145 return changedBlocks , io .EOF
145146 }
146- // if VARIABLE_LENGTH type is enabled, return blocks extend instead of individual blocks.
147- blockMetadata := createBlockMetadata (blockIndex , cb .blockSize )
148- if extendBlock (changedBlocks , csi .BlockMetadataType (cb .blockMetadataType ), blockIndex , cb .blockSize ) {
149- changedBlocks [len (changedBlocks )- 1 ].SizeBytes += cb .blockSize
150- cb .offset += cb .blockSize
151- blockIndex ++
152- continue
147+ // return only allocated blocks.
148+ if blockChanged (zeroBlock , tBuffer [:targetReadBytes ]) {
149+ // if VARIABLE_LENGTH type is enabled, return blocks extend instead of individual blocks.
150+ blockMetadata := createBlockMetadata (blockIndex , cb .blockSize )
151+ if extendBlock (changedBlocks , csi .BlockMetadataType (cb .blockMetadataType ), blockIndex , cb .blockSize ) {
152+ changedBlocks [len (changedBlocks )- 1 ].SizeBytes += cb .blockSize
153+ cb .offset += cb .blockSize
154+ blockIndex ++
155+ continue
156+ }
157+ changedBlocks = append (changedBlocks , blockMetadata )
153158 }
154- changedBlocks = append ( changedBlocks , blockMetadata )
159+
155160 cb .offset += cb .blockSize
156161 blockIndex ++
157162 continue
0 commit comments