Wednesday, 15 February 2012

c++ - implementing block storage for a database -



c++ - implementing block storage for a database -

for database class, implementing our own database, , having problem how implement block storage in c++ (where each block 1024 bytes).

we store each database table randomly accessible collection of blocks on hard disk, first block file header, dedicated meta info (block 0), , each subsequent block dedicated storing rows of table. blocks written hard disk files. have 1 block "in-memory" buffer; can read , edit info in buffer, , when ready, write in-memory buffer disk.

i think ok conceptualizing in-memory buffer, having problem how write blocks of memory files. have 2 ideas, each own difficulties:

idea 1

create class memoryblock 1024 bytes. each memoryblock can store arbitrary info (file header or rows of table). store each table single file writing array of memoryblocks file.

difficulty: can update single block in middle of file? understanding files must overwritten or appended to. if have file of 3 memoryblocks (blocks 0-2), , want update row in block 1, can pull block 1 buffer, edit it, , write middle of file, or have pull entire file memory, edit want to, , overwrite original file?

idea 2

store each block separate file on disk. allow me randomly access block , write disk without having worry rest of table

difficulty: i'm not sure if enforcing 1024 byte block size. there way require each file not exceed 1024 bytes?

i not married either idea, appreciative of input helps me improve understand block storage in database management systems.

edit: @zaufi points out, 1024 byte block sizes atypical. meant type 4096 byte blocks when writing this.

ohh man, need read smth databases internals...

here 5 cents: both ideas bad! why decided utilize 1024 bytes blocks??? physical sector size modern hdd 4096 bytes! disk controllers have cache 4m-6m-8m-16m-... writing 1k wasting resources...

and btw, updating smth in middle of file bad idea... if performance not concern, can do...

before reinvent wheel seek research typical approaches used in various dmbs... 1 more (simple) source read: google leveldb , firends... -- give ideas!

c++ memory memory-management block database

No comments:

Post a Comment