EldoS | Feel safer!

Software components for data protection, secure storage and transfer

Inserting documents to SFS File in MultiThreaded environment

Also by EldoS: CallbackRegistry
A component to monitor and control Windows registry access and create virtual registry keys.
#11179
Posted: 09/29/2009 07:09:00
by gürcan yücel (Standard support level)
Joined: 09/28/2009
Posts: 10

Hi All,
I have a program that have 10 threads. Every thread reads a blob data (which is a file) from DB and tries to insert it to a SolFS file. In evert thread I have a function to insert the document. In this function I always creating the storage and free it. In some threads Im getting;
"Storage Error: Can not perform this opeartion on read only storage"

Here is my Thread function;
Function TFileConvert.MoveToStorage(FDocNo:Integer;FFolder:String;FFileName:String):Boolean;
Var
FSTName:String;
Begin
try
FSTName:=f_convert.SavePath+InttoStr(TRUNC(FDocNo/10000)+1)+'.SF';
FStorage:=TSolFSStorage.Create(nil);
FStorage.FileName:=FSTName;
FStorage.PageSize:=4096;
if FileExists(FSTName) then
FStorage.Open(somOpenExisting)
else
FStorage.Open(somCreateAlways);
FStorage.FilesToStorage(f_convert.SavePath,ExtractFileName(FFileName),faAnyFile,False,FFolder,omAll);
FreeAndNil(FStorage);
Result:=True;
except
on e:exception do
begin
f_convert.Memo1.Lines.Add('EXCEPTION:'+IntToStr(FDocNo)+':'+e.Message);
Result:=False;
end;
end;
End;


According to FDocNO, storage changes. For this reason I cant create the storage first. What is doing wrong?

Regards.
#11180
Posted: 09/29/2009 07:51:32
by Alexander Plas (Team)

Hello

You have to open the storage file one time outside your threads, use this one instance of TSolFSStorage class in all threads and them close storage instance when all threads done.

This error may occur when you open already opened storage.
#11181
Posted: 09/29/2009 07:57:09
by gürcan yücel (Standard support level)
Joined: 09/28/2009
Posts: 10

Hi Plas,
Ok. Understand. In my case there is multiple storages. For this reason every thread have its own TSolFSStorage object. I thought that it can be done via this way.

I understand that its not possible to write SolFS storage in multi threaded environment if there is multiple storage files to chose. Is it possible to just READ in multi threaded environment?

Regards.
#11182
Posted: 09/29/2009 08:03:01
by Eugene Mayevski (Team)

You can open the same storage from multiple threads in read-only mode, this is possible. If you need to write to one storage from multiple threads, then you need to do as Alex mentioned, - open the storage once and use one TSolFSStorage object from several threads (this is safe). You can also open multiple different storages from different threads.

In other words, the only thing you can't do is open the same storage in read-write mode several times concurrently (from different threads of the process or from different processes, it doesn't matter). Other combinations work.


Sincerely yours
Eugene Mayevski
#11183
Posted: 09/29/2009 08:05:38
by Alexander Plas (Team)

No, there is a rule: one storage file – one storage object. SolFS maintains in-memory cache and this makes impossible to read and write simultaneously with different storage objects.

You can read and write simultaneously with Driver Edition, or maintain a pool of storage objects manually with appropriate synchronization.
#11184
Posted: 09/29/2009 08:24:51
by gürcan yücel (Standard support level)
Joined: 09/28/2009
Posts: 10

Thank you for the answer.
What do you mean pool of storage objects?
Creating every possible storage and waiting for insert or select? Within a proper critical section?

Regards.
#11190
Posted: 09/29/2009 08:47:32
by Alexander Plas (Team)

Quote
Thank you for the answer.
What do you mean pool of storage objects?
Creating every possible storage and waiting for insert or select? Within a proper critical section?

Yes, something likes this. Alternatively, you may create and open storage objects on demand and then close and destroy it after some period of inactivity. All storage opens and closes must be synchronized with the critical section.
Also by EldoS: CallbackRegistry
A component to monitor and control Windows registry access and create virtual registry keys.

Reply

Statistics

Topic viewed 3236 times

Number of guests: 1, registered members: 0, in total hidden: 0




|

Back to top

As of July 15, 2016 EldoS business operates as a division of /n software, inc. For more information, please read the announcement.

Got it!