TmStorage開源存儲引擎
TmStorage 是一個用 .NET 開發(fā)的虛擬文件系統(tǒng),用來存儲流數(shù)據(jù)。使用扁平結(jié)構進行數(shù)據(jù)存儲,通過類型為 GUID 的流 id 來引用數(shù)據(jù)。
TmStorage 使用一個主文件用來存儲所有流數(shù)據(jù)。主文件被分成多個可變長度的段,每個段只由一個流來占用。每個流由 0 到多個段組成。
每個段包含一個段的元數(shù)據(jù),這些元數(shù)據(jù)存放在段的起始位置,包含如下信息:
段大小 (Int64)
下一個段的位置,如果是最后一個段則為 null(Int64)
元數(shù)據(jù)的校驗和 (Int)
為了防止碎片化嚴重,段大小固定為 512 字節(jié)的整數(shù)倍。
使用實例:
Image image = Image.FromFile("c:\\image.png");
Storage storage = new Storage("c:\\images.storage", "c:\\images.storagelog");
Guid streamId = Guid.NewGuid();
storage.StartTransaction();
try{
Stream stream = storage.CreateStream(streamId);
image.Save(stream, ImageFormat.Png);
stream.Close();
storage.CommitTransaction();
}finally{
storage.RollbackTransaction();
}評論
圖片
表情
