How to “transaction” a IO operation and a database execution?

前端 未结 2 1298
温柔的废话
温柔的废话 2021-01-14 01:57

I have service that contains a processor running, and it do two things:

1- Create a file in a directory.
2- Set your own status to \"Processed\".
         


        
2条回答
  •  猫巷女王i
    2021-01-14 02:17

    You didn't specify the database server, but Microsoft SQL Server 2008 R2 supports streaming file data as part of a transaction.

    See: https://technet.microsoft.com/en-us/library/bb933993%28v=sql.105%29.aspx

    Transactional Durability
    With FILESTREAM, upon transaction commit, the Database Engine ensures transaction durability for FILESTREAM BLOB data that is modified from the file system streaming access.
    

    For very large files, I wouldn't recommend it, because you often want the transaction to be as quick as possible when you have a lot of simultaneous transactions.

    I'd normally use a compensation behaviour, e.g. storing status in a database and when a service is restarted, get it to first check for operations which have started but not completed and finish them off.

    1. Operation started on Server x at datetime y
    2. Operation completed on Server x at datetime y

提交回复
热议问题