Text storage, this is the one I rarely go to the implementation of specific areas of application before.
How will talk about text database from Part I: Technical Principle Autumn Park QBlog: performance optimization articles: separate read and write text database (XVIII) , a seen out of the application, and therefore have the urge to dash.
Of course, from the above, it can be seen: the basic text-based application write simple, gently and strictly speaking a little "Database" not the edge state is not enough.
I thought "text database", no matter how simple, they have it should have the following:
2 : primary key ID, not when the GUID, ye have to right across the self-energizing ID (application habit everyone).
3 : Can add, modify, delete data.
4 : The best can query, sorting, paging, as the grouping may require a high point.
5 : There is preferably further concurrency control.
Look back Autumn Park QBlog current applications are:
2 : 1 basis point, can only be applied to read the text, and "database" has nothing to do.
From the above it is the current application, not entirely up to the realm of text database applications.
Of course, with text-based applications, and therefore the logical extension of a text "Text Database" to generate a little interest and impulse and very natural.
So, I search the Internet a bit, "the text database" and found almost no .net community in its presence, but added php community had let EXTRAORDINARY SPLENDOR large, this is why?
Why is this? Presumably to the following:
When the basic advantages of using text databases:
have to explain, I can only say: everyone is saved disk, direct deposit a certain amount of certainty around the storage structure of the rules after the deposit faster than the database, of course, the more backward the more complex , not easy to say.
2 : simple access operation:
do what ADO.NET, direct System.IO.File can handle, easy multi-ah!
When the basic disadvantage with text databases:
2 : Concurrent does not seem good
3 : delete and modify operation is not good
4 : To transform into a "text database" There is a lot to deal with something important:
A: This is an increase from ID loud noise out ah?
b: To find this Zezheng ah?
c: To sort this Zezheng ah?
Basic application scenarios with the applicable text databases:
single (table) small amount of text data: the following data 100,000, 10M size of the following (the disposable loading operation into memory, it would be a database memory, speed crashed) .
2 : large-scale application, supplemented text database:
by some database dispersed fragmented text, by reducing the pressure in the primary database.
3 : medium-sized applications, text-oriented database:
this is not to say that bad, not that good, need to have some strong technical support team.
In order to better play "text database" initiative, I spent some time its a little research and thinking, and everyone to share the following experience:
1: storage structure
So here is the point of technology: How to read json and json output resolution.
Here: CYQ.Data . V3 0 frame open source version ( downloaded ) in a JsonHelper, can generate data Json, json string can be parsed into KeyValue key value, may be of interest to study.
So, basic reading and taking solved.
2: Data Insert
3: update, delete
One way: simply type [this actually quite good, so from the point of view text database application scenarios, the basic requirements are not too high]
will re-export the entire table json , once again rewrite the text on it.
Second way: Complex [This is a little more performance considerations for text database pursuit had some too little, because if it's too complicated, why not look for other databases, text does not plan a simple what]
the more painful, there is also gives the idea of a personal idea:
1 : when a given table structure, must be a good length of each field, so you fix a total maximum line length.
2 : When you write a line of data, the total length of time is not enough, back up empty (usually written like \ 0).
3 : when updated or deleted according to (ID-1) * total length of line, positioned to the starting position of the writing, and then rewritten to a line, if the full row is deleted when the write null (\ 0).
In fact, here is space for time, and when data is deleted, the text size did not change, is not it a bit like access it?
Two pins in the above manner, the point here is sample code:
fs.Seek ( start position location to be written , SeekOrigin.Current);
fs.Write (content written .. ...);
fs.Close ();
4: increment ID gnaw out
The following sample code is given a reference:
{
int lastIndex = _Table.Rows.Count - 1 ;
do
{
if (lastIndex >= 0 )
{
if (_Table.Rows[lastIndex][ 0 ].IsNull)
{
lastIndex -- ;
}
else
{
maxID = Convert.ToInt32(_Table.Rows[lastIndex][ 0 ].Value) + 1 ;
}
}
else
{
maxID = 1 ;
}
}
while (maxID == 0 );
}
else
{
maxID = 1 ;
}
}
else
{
throw new Exception( " Increment id only use for int type " );
}
}
return maxID;
}
}
5: Query how to do
6: Sorting how to do
7: Single-process concurrency control how
8: multi-process concurrency control how
Finally, I want to be out of the way: in the process of preparing to change the text, read text last modified time for comparison, thus achieving a relatively controlled.
to sum up:
After personally feel completely solve the above problem, basically forming a simple text database also, of course, you can also continue to pursue up.
However, a text database, toss did not need too complicated, after all text database, or to simply dominated.
If NoSql will be popular, why not let text database also .net community also out of the limelight, to grow into a .Net world a wonderful work!
Reproduced in: https: //my.oschina.net/secyaher/blog/274218