37. 一次写入的具体过程 Put 数据库层的操作 Put implement 数据库写入一条记录的逻辑步骤 Write into file 文件系统层面的原理
38. put Access method_mutex(no limit while reading but only one writing is allowed) Hash key-buf index of bucket Hdb->async (flush the rec-pool to disk) 2nd hash(using the 8-bit in the little end) to access 1/256 record_mutex(muti-read allowed, one write in a time)
39. Put implement Out the cache Bucket-index to get offset in the bucket Read the rec-head in offset 0f bucket If free-rec ,pread(hdb-fd, offset). Else bsearch(2nd-hash) the bucket to find free-rec Put the recordbody(depend on the type of the put) Ps: using mmap to avoid too much system call
40. Write it into file 把记录按格式填入要一次写入磁盘的buff 找到合适(或者合并相邻)空闲块给buff,递归写入 然后修改所属桶的桶内偏移 Free block pool 机制(fb数组(可持久化),用完再文件末尾追加) 缓冲池机制(格式同磁盘格式,可直接写入,mmap实现)
42. Restore from ulog Tcrdb restore lock rdb, fullfil the package, tcrdbsend Ttserver proc(log,register the callback), serstart Epoll (in the following slids) Tc ulog adb restore 1. new a logreader(list the logfile, match the timestamp, lock the specific log file) 2. reader(read logrecord from disk to mem, fullfil the struct) 3. parse the log-struct , adbredo(call the tchfunction)
43. Thread Pool Model listen epoll/kqueue accept the client connection if the event is about the listener first of all, the listening socket is enqueued into the epoll queue queue epoll_ctl(add) accept queue back if keep-alive epoll_wait task manager epoll_ctl(del) queue enqueue move the readable client socket from the epoll queue to the task queue deque worker thread worker thread do each task worker thread
44. Ttserver Prepare sock-obj, task-obj,req-obj Log in every step(can choose the aio) Face to adb(logical) Database skeleton(对后台引擎api接口的封装,接入adb(abstract db),对server那层透明) Timeout control the rythm Tcrmgr可以热机备份tch文件到异地(不能写入)