My client-server application simulates a showcase (like a Facebook one). As with every client server application, the server might crash, or go down for electrical deseases or whatever, therefore it was crucial to elaborate a backup system. As long as I have to write stuff on the showcase everything's fine: you write the message on the single-linked-list I use to store the messages and I also write them down on the backup file (which is a text file... yea, I know, but we didn't have time to see other types of file in the course, but still...). Assume the file is like this:
MEX1:
TEXT1
MEX2:
TEXT2
MEX3:
TEXT3
And so on...
The problem is when a user wants do delete the message. Deleting a node from a single linked list is child's play, the problem is that the same message should be deleted from the backup file, too.
Now, reading here on Stack Overflow and on every other web site I found about the subject, seems like I must:
- Create another backup file;
- Copy everything until the portion of the file I do not need;
- Skip it;
- Start copying again until the end;
- Delete old file;
- Use new file as backup file;
Which would be fine... unless I have to delete messages from the application very often. My professor is like a sniper: if I give him the copy-paste solution he WILL say "What if a famous person dies and everyone starts posting and deleting stuff from the showcase?".
And he's right, you know. I may have to delete tens of messages per minute, which is not ok with the copy-paste solution. If I have 1000 messages of 100 lines each on the file and I have to delete one message only I'll have to copy 999000 lines. Do it for ten times in a minute, it's crazy.
Another way around would be that of using more files instead of only one. But then I'll need a sort of sorting in order to make information accessible in short time, and eventually these files will grow bigger. Therefore I would need to split them, but how do I decide when to split them?
And, by the way, the problem stays still. I have reduced the amount of information to copy and then paste, but eventually the problem will rise again. And, after all, I'll have my server machine filled with backup files.
So, could you suggest me some kind of solution to just delete a specific portion of the file, without copy-pasting everything else?
In the above example, I want to delete Text2 message. So I want to delete from MEX2: to the end of TEXT2. It should look like this:
MEX1:
TEXT1
MEX3:
TEXT3
Every suggestion is appriciated. Thanks.