Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 684487
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T01:49:20+00:00 2026-05-14T01:49:20+00:00

i am working on a online file management project.In which we are storing references

  • 0

i am working on a online file management project.In which we are storing references on the database(sql server) and files data on the on file system;.In which we are facing a problem of coordination between file system and database while we are uploading a file and also in case of deleting a file that first we create a reference in the data base or store files on file system;;the problem is that if create a reference in the database first and then storing a file on file system.bur while storing files on the file system any type of error occur.then reference for that file is created in the database but no file data on the file system;; please give me some solution how to deal with such situation;;i am badly in need of it;;
and reason for that?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T01:49:21+00:00Added an answer on May 14, 2026 at 1:49 am

    This actually a little easier than you think it is.

    First, you need to decide the “single source of truth”.

    That is, either the file system or the DB is correct at any given point in time, which one is it?

    The reason for this is that it makes it easier to resolve conflicts.

    You should assume that the database is your Source, and that the file system is a shadow of the database. This seems counter intuitive, since, how can an entry exist in the DB if it’s not in the file system. Obviously it can’t. But, basically, if the file isn’t in the DB, then “it doesn’t exist” anyway. So, the file system reflects the state of the DB, not the other way around.

    Given these assumptions, you end up with these conflict resolution rules.

    For any given file:

    File Exists    DB Entry Exists   Action
       Yes            Yes            No action, normal state
       No             Yes            Error -- missing file, "should never happen"
       No             No             No action, normal state
       Yes            No             Delete the file, but no error.
    

    When uploading files, there’s exists a grey area — i.e. when a file is uploaded but not yet acknowledged by the DB.

    The way to solve this you need to upload the file in a staging mode.

    An easy way to do this is to upload the file to a different directory, but on the same physical file system, or to upload it to the final place using a temporary file name. Either way, the file is easily identifiable as being “in process” by it’s name or location.

    You want to have this file “staged” on the same file system for two reasons. One, disk space. If the disk doesn’t fill up when you upload, then you KNOW it’s going to fit in its final resting place (it’s already “reserved” the space). Two, when you finally place the file, that operation must be atomic. File rename operations on the same filesystem, are atomic on modern filesystems. Basically, you can’t have the file “half way renamed”, even if it inevitably “overwrites” an existing file (the original is deleted during the rename operation).

    Once staged, your operation becomes:

    Start DB transaction
    Rename file
    Add DB record
    Commit transaction
    

    If the rename file action fails, you abort and roll back the DB transaction, thus the entry. If the rename succeeds, and the DB fails? Then you have State #4, listed above. Retry the upload until it succeeds.

    To delete a file, do this:

    Start DB Transaction
    Delete DB record
    Commit transaction
    Delete file from file system
    

    If the DB delete fails, you don’t delete the file. If the DB delete succeeds, and the file deletion fails, then we’re back to State #4.

    Finally, you have a reaper process that regularly (daily, weekly, whatever) compares the DB to the file system, deleting any files that are not in the database. Since the DB is the “Single source of truth”, the two stores will eventually be in sync.

    If a file goes missing that has a DB record, then you have “data corruption”. Don’t do that. It’s a bug, or someone is walking over your file system.

    The retry characteristics of the upload process and the fast fail of the delete process gives you a pseudo two phase commit process that easy to check what’s right and wrong, and easy to correct to the proper state.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on project -online file management where we have to tore file
I have developed an online leave management system in PHP, MySQL, which is working
I am working on a file management application which parses excel files from the
While setting up an online file management system, and now I have hit a
I am working on online pdf library project. In this I have a feature
I am working on an online video repository system for a client, written mostly
I'm working on an online forex trading system and a while back we have
I'm working on an online store. I have it setup on my testing server.
I'm working on a online game. I got some problems with inserting new data
I am working on a batch file to read through the files in a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.