Project

General

Profile

Actions

Bug #2535

open

Reloading ptr<C> in a std::map database

Added by Saif Rehman about 10 years ago. Updated almost 10 years ago.

Status:
Feedback
Priority:
Normal
Assignee:
Target version:
-
Start date:
01/03/2014
Due date:
% Done:

0%

Estimated time:

Description

Hi,

I have an std::map which stores all rows in ptrs. However when the values are modified externally(and not from the Dbo::Session) and reloaded from the database to the std::map, all rows which were modified in the database do shows otherwise when checked with ptr values.

The test file is attached which prints expected and actual values.


Files

DboTestReload.C (3.33 KB) DboTestReload.C Saif Rehman, 01/03/2014 10:00 PM
WtSessionDisconnect.patch (8.36 KB) WtSessionDisconnect.patch Saif Rehman, 05/23/2014 10:47 PM
Actions #1

Updated by Koen Deforche about 10 years ago

  • Status changed from New to Feedback

Hey Saif,

Wt will not update the values of existing Dbo objects unless you tell it to. The logic is that you will want to keep the initial value because presumably that's a value you used some how (e.g. showed to the user) or made a calculation with it.

To reread all values you need to first call session.rereadAll() for all pointers, or ptr.reread() on an individual object.

Regards,

koen

Actions #2

Updated by Saif Rehman about 10 years ago

Thanks for the feedback Koen but that is not what I want to do. I have a memory stored database synced with a backend. It loads data once into ptrs and keeps them in a container.

For example lets assume the database stores all configuration data. I want to keep all "C" in ptr and pointers pointing to the same data because if the database gets updated during a session, the configuration used in the session and the configuration after database is modified and reloaded would not be the same.

What I want is every time I reload new ptr will be allocated/created from backend, the old ptr will held in a session until the session loses scope on it(session destroyed), after which it will be automatically deallocated.

Maybe this could be added as a feature? If not, please let me know on a workaround for this.

Actions #3

Updated by Saif Rehman about 10 years ago

Saif Rehman wrote:

What I want is every time I reload new ptr will be allocated/created from backend, the old ptr will held in a session until the session loses scope on it(session destroyed), after which it will be automatically deallocated.

Grammar correction

What I want is every time I reload, new ptrs will be allocated/created from backend, the old ptr will held in a session until the session loses scope on it(session destroyed), after which it will be automatically deallocated.

Actions #4

Updated by Koen Deforche about 10 years ago

Hey Saif,

I think I understand what you want but it would create all kind of nasty additional questions: suppose:

  • oldPtr stores old value
  • newPtr stores new value

What should (oldPtr == newPtr) return? (they have the same id's but not same values?)

Perhaps in your situation you should really create a new Wt::Dbo::Session for each reload() ?

Regards,

koen

Actions #5

Updated by Saif Rehman about 10 years ago

oldPtr == newPtr would return false since they won't be referencing the same objects.

That sounds like a good solution. Is it safe to delete a session and continue using with ptr for reading purposes? And I've also posted a feature issue for ptr which would be useful in this situation.

Actions #6

Updated by Koen Deforche about 10 years ago

  • Assignee set to Koen Deforche

Hey,

No a session should outlive all of the pointers (otherwise you'll see warnings about orphaned ptr's which is not safe to ignore).

To be honest, I believe what you want may be useful and shouldn't be straight forward to integrate in Wt::Dbo. If you are willing to add it, I can give some guidance.

Regards,

koen

Actions #7

Updated by Saif Rehman about 10 years ago

I am willing to add it, and I'd appreciate the guidance. Where should I start?

Actions #8

Updated by Koen Deforche about 10 years ago

Hey,

Your new function should clean up the registry of objects maintained in Session. This is not too different from what currently happens in ~Session. You should thus add a new virtual function to Session::MappingInfo and its type-specific implementation Session::Mapping which simply cleans the registry without deleting objects.

Finally, you need to mark the MetaDboBase class with a new flag which is similar to Orphaned in meaning, they no longer are connected to a Session.

I hope that points you already in the right direction.

Regards,

koen

Actions #9

Updated by Saif Rehman about 10 years ago

Thanks koen. And I wanna make sure which new function are you talking about? I am assuming reload function?

Actions #10

Updated by Koen Deforche about 10 years ago

Hey,

I think we should have a new function which simply 'evicts' existing pointers from active management by the Session, instead of reloading them as is the current behaviour of reload().

Regards,

koen

Actions #11

Updated by Saif Rehman almost 10 years ago

"you need to mark the MetaDboBase class with a new flag which is similar to Orphaned in meaning"

Does that mean I should create a new flag 'Disconnected' or just simply mark it Orphaned?

Actions #12

Updated by Saif Rehman almost 10 years ago

Attached is the patch file for the implementation of Dbo::Session::disconnectAll(). I'm setting the session ptr in dbo as null and setting the ptr to 'Disconnected' flag that can not flush changes.

Actions #13

Updated by Saif Rehman almost 10 years ago

I'm not sure if removing Dbo::Session from ptr is a good idea. However, I only did that to prevent transactions from auto-committing changes in a disconnected ptr.

Actions #14

Updated by Saif Rehman almost 10 years ago

Would it be safe to disconnect a certain ptr or would it possibly cause a problem with the mapping?

Actions

Also available in: Atom PDF