Search This Blog

Saturday, 17 September 2011

How to sync large size database with sync framework


By using sync framework 2.1 we can easily sync databases frequently by scheduling sync with some interval. In one of our project we have to give chance for client to schedule sync frequently. We have implemented the functionalities using sync framework 2.1 with ASP.Net mvc application. You can go through the main codes for sync here.
It was working fine until we are testing with large size db (greater than 10 GB). When we are testing with large size db, we got error in the middle of sync process.
The error is  “There is no enough space for the disk”. Then we are increased the size of the target db to 20 GB (source db 10GB) but got same error. We are search on the google and cannot found enough support for the issue. We are going behind the issue and after some days we have found the root cause of the issue. It was not related to sync framework. When sync process is running, a log file will be writing as backend process to the location “C:\Resources\temp\7aad4070ce51495c82cde6b1d410aa65.WorkerRole1\RoleTemp” of Virtual Machine in the worker role (WaHostBootstrapper). The size of this log file will be increasing continuously and there is some limitation for the size of the file (normally 60 mb). Obviously it will take long time to sync large db and log file size increased and crashed once the max size exceeded. At last we have found the solution and now our application can sync large db without any error. The solution is given below.
1.    We need to extend the max size of the log file. We can achieve it by following code in the “ServiceDefinition.csdef”
<LocalResources>
      <LocalStorage name=”localStoreOne” sizeInMB=”20480″ cleanOnRoleRecycle=”true” />
    </LocalResources>
   Name ( localStoreOne) : indicates your local storage name
    sizeInMB : indicates the maximum size of the log file you want to give.
    cleanOnRoleRecycle : It will delete and recreated log file for each workerrole when it is        set to true
2.    In the “OnStart()” method in the workerrole we need to map the temp folder by using following code.
string customTempLocalResourcePath =
       RoleEnvironment.GetLocalResource(“localStoreOne”).RootPath;
       Environment.SetEnvironmentVariable(“TMP”, customTempLocalResourcePath);
       Environment.SetEnvironmentVariable(“TEMP”, customTempLocalResourcePath);
Then we can see that log file is archived in the middle of sync with some size, and can hold up to the size that we mentioned in the ServiceDefenition file. It is better to  cleanOnRoleRecycle is set to true, then it will automatically deleted the log files once the worker role restart and recreated again.

No comments:

Post a Comment