RaptorDB-Document icon indicating copy to clipboard operation
RaptorDB-Document copied to clipboard

Inconsistency when consulting data

Open frohlichcortezh opened this issue 5 years ago • 9 comments

My APP logic is:

  1. Get data from an API
  2. Delete the current data in raptorDB
  3. Insert the data from the API in the DB
  4. use the data from the DB

Randomly I get different results from the DB when querying it. I've added some logs in the APP to try to understand it, since it doesn't happen in my machine but occurs repeatedly in the production machine.

2020-02-24 09:42:38.9950|TRACE|application.App|Plannings API: 2 (Amount of data returned from DB) 2020-02-24 09:42:38.9950|TRACE|application.App|Plannings DB: 2 (Querying the data from the DB) 2020-02-24 09:42:38.9950|TRACE|application.App|Plannings deleted: 2 (Data deleted from the DB) 2020-02-24 09:42:38.9950|TRACE|application.App|Plannings inserted: 2 (Data inserted from the DB) 2020-02-24 09:42:38.9950|TRACE|application.App|Plannings DB: 2 (Querying the DB just after the insert to check if the amount is the same) 2020-02-24 09:42:41.7042|TRACE|application.App|LoadPlanningCollaborateur -> Planning.Count: 2 (Checking the amount again) ... user interaction without changing DB ... 2020-02-24 09:43:51.2066|TRACE|application.App|LoadPlanningCollaborateur -> Planning.Count: 0 (Same query, same parameters, no data returned)

It can return sometimes one row.

here's my view

    /// <summary>
    /// View des plannings
    /// </summary>
    [RegisterView]
    public class PlanningView : View<Planning> 
    {
        public PlanningView()
        {
            this.isPrimaryList = true;
            this.Name = nameof(PlanningView);
            this.isActive = true;
            this.BackgroundIndexing = false;
            this.TransactionMode = true;
            this.Schema = typeof(PlanningViewRowSchema);
            this.Mapper = (IMapAPI api, Guid docid, Planning doc) => api.EmitObject(docid, doc);
            this.Version = 2;
        }
    }

Querying the DB :

return DB.Query<PlanningViewRowSchema>(filter);

Saving to DB :

        public Guid PutPlanning(Planning Planning)
        {
            if (Planning.DateCreation == DateTime.MinValue)
                Planning.DateCreation = DateTime.Now;

            if (DB.Save<PlanningViewRowSchema>(Planning.Id, PlanningViewRowSchema.FromPlanning(Planning)))
                return Planning.Id;
            else
                return Guid.Empty;
        }

Deleting from DB:

        public int DeletePlannings(List<Planning> Plannings)
        {
            int count = 0;
            foreach (var planning in Plannings)
            {
                if (DB.Delete(planning.Id))
                    count += 1;
            }
            return count;
        }

I've tried changing the view parameters like using this.TransactionMode = true; but it didn't change the results. Any help is welcomed.

frohlichcortezh avatar Feb 24 '20 09:02 frohlichcortezh

Also, at first I was interacting with the DB with the view model rather than the schema like :

DB.Save<Planning>(Planning.Id, Planning)

DB.Query<Planning>(filter);

Changing to the RowSchema seemed to work at first, but after more extensive testing the errors returned.

frohlichcortezh avatar Feb 24 '20 09:02 frohlichcortezh

Is your prod server running on IIS?

mgholam avatar Feb 24 '20 12:02 mgholam

No

frohlichcortezh avatar Feb 24 '20 13:02 frohlichcortezh

How long before the inconsistencies occur in prod (since you don't see them in dev)?

Do you have multiple concurrent users in prod?

mgholam avatar Feb 24 '20 14:02 mgholam

Can't say with certainty since it can work around while I'm doing some tests in prod, and then a couple of hours later when the user is gonna test we got the incosistencies.

No, single user.

frohlichcortezh avatar Feb 24 '20 14:02 frohlichcortezh

Are the deletes done in parallel (is your application threaded)?

mgholam avatar Feb 24 '20 15:02 mgholam

No, single threaded.

frohlichcortezh avatar Feb 24 '20 15:02 frohlichcortezh

Are you on the latest build?

mgholam avatar Feb 24 '20 16:02 mgholam

Yes, 4.0.9. My project targets net461 and netstandard2.1.

frohlichcortezh avatar Feb 25 '20 08:02 frohlichcortezh