Synchronizing a PowerShell based database using a binary file

I wrote a database application using a binary as storage. it is available via powershell cmdlets.

You can put information into the database using put-, and you can read information using get -.

The problem is synchronization. What's the best way to ensure that the cmdlets don't access the file at the same time?

The path must have exclusive access, or no other authors or readers will be able to access the file. The recipient does not need exclusive access and readers can access the database at the same time.

Am I best using a file based locking mechanism or a .NET based synchronization mechanism?

+1


source to share


3 answers


I am not aware of any .NET based synchronization mechanisms that would be relevant here (read on - I am making the assumption that this may not be correct).

If you must have exclusive access to "put", then either (a) file-based locking or (b) database-based locking may be appropriate. For example, the "put" command might first check a special field in the database to see if it can get exclusive access; if possible, it will update this field to indicate that exclusive access has already been made, preventing a restart.



If I'm interpreting your question correctly, it is possible for this database to be accessed by multiple computers, which means that the mutex doesn't really work as they are meant for inter-thread synchronization. If it is not, and only one computer is accessing the file at any one time, then the mutex will work well.

0


source


I think there is a mutex here .



0


source


I think the mutex method should now be in effect. While PowerShell v2 makes it easy to remove external scripts, I think worrying about it at this point just gets in the way of the fast implementation of PowerShell v1.

The database I am using is a plain old binary, so unfortunately I cannot expect the database to sync for me.

With a mutex that can interact with multiple databases at the same time, I need to use a named mutex using the file path as the name so that I can ensure that the mutexes are unique for each database

0


source







All Articles