Comments (7)
PtrToEntity->PtrToObject renamed in my previous comment.
Thanks a lot for good examples.
It's time to close the issue.
Good luck.
from dbreeze.
Hi, unless you setup
tran.ObjectInsert(tableName, newObject, speedUpdate=true);
it is possible that even changed entity will reside the same disk space (if its size will be less or equal to the previous entity version size).
So, this logic can break your sync.
But if you setup speedUpdate to true (that is actually good not for each situation) you will get higher disk space consumption.
I would suggest to change sync event tracing logic.
Serialized objects can be compared on the byte[] level using extension function from DBreeze.Utils
var theyAreEqual = byte[] {2,3,4}._ByteArrayEquals(new byte[]{2,3,5});
from dbreeze.
Version 1.91 solves it and DBreezeObjectInsertResult has now PtrToObject,
also DBreezeObjectInsertResult has EntityWasInserted, so the code could look like
DBreezeObjectInsertResult<TEntity> res = tran.ObjectInsert(tableName, newObject);
if(res.EntityWasInserted )
tran.Insert<byte[], byte[]>(syncTableName, 1.ToIndex(_synchronizationManager.SyncTransactionId, id), res.PtrToObject);
Hopefully, it can be retrieved by tran.ObjectGetByFixedAddress
from dbreeze.
Thanks for quick response and suggestion!
Could you please shed the light on following situation (see code below):
class Entity()
{
int Id {get;set;}
string Name {get; set;}
}
//#1 step
var newEntity = new Entity() {Id = 1, Name = "New Entity"};
var newEntityRes = tran.ObjectInsert(tableName, new DBreezeObject<Entity
>{ Entity = newEntity }, true);
var newEntityPtr = newEntityRes.PtrToObject;
//#2 step
var smallerEntity = new Entity() {Id = 1, Name = "Entity"};
var smallerEntityRes = tran.ObjectInsert(tableName, new DBreezeObject<Entity
>{ Entity = smallerEntity}, false);
var smallerEntityPtr = smallerEntityRes.PtrToObject;
//#3 step
var biggerEntity = new Entity() {Id = 1, Name = "Bigger Entity"};
var biggerEntityRes = tran.ObjectInsert(tableName, new DBreezeObject<Entity
>{ Entity = biggerEntity}, false);
var biggerEntityPtr = biggerEntityRes.PtrToObject;
//#4 step
var row = tran.SelectDirect<int, byte[]>("t1", newEntityPtr);
var exists = row.Exists;
My questions is:
1)
newEntityPtr == smallerEntityPtr (always)
newEntityPtr == biggerEntityPtr (if there are no Entities with with Id>1)
newEntityPtr != biggerEntityPtr otherwise
what value of exists variable in step 4:
my answer is:
true - if there are no Entities with with Id>1
false - otherwise
Regards!
from dbreeze.
First of all, in the newest NuGet release 1.91 renamed PtrToEntity->PtrToObject.
//Inserting new entity
using (var tran = engine.GetTransaction())
{
var x1 = tran.ObjectInsert<byte[]>("t1", new DBreeze.Objects.DBreezeObject<byte[]>()
{
Entity = new byte[] { 1, 2, 3 },
//NewEntity = true, //this is another speed optimzation flag, can be skipped until is really necessary
Indexes = new List<DBreeze.Objects.DBreezeIndex>()
{
new DBreeze.Objects.DBreezeIndex(1, (long)1){ PrimaryIndex = true }
}
}, false); //inserting entity
tran.Commit();
}
//Testing updates
using (var tran = engine.GetTransaction())
{
var x1 = tran.ObjectInsert<byte[]>("t1", new DBreeze.Objects.DBreezeObject<byte[]>()
{
Entity = new byte[] { 1, 2, 3 },
Indexes = new List<DBreeze.Objects.DBreezeIndex>()
{
new DBreeze.Objects.DBreezeIndex(1, (long)1){ PrimaryIndex = true }
}
}, false); //Speed insert is off, the equal entity on the level of byte[] will not be overwritten
//--> will be false
Console.Write(x1.EntityWasInserted);
x1 = tran.ObjectInsert<byte[]>("t1", new DBreeze.Objects.DBreezeObject<byte[]>()
{
Entity = new byte[] { 1, 2, 3 },
Indexes = new List<DBreeze.Objects.DBreezeIndex>()
{
new DBreeze.Objects.DBreezeIndex(1, (long)1){ PrimaryIndex = true }
}
}, true); //Speed insert is on - entity will be overwritten (new PtToObject will be generated)
//--> will be true
Console.Write(x1.EntityWasInserted);
x1 = tran.ObjectInsert<byte[]>("t1", new DBreeze.Objects.DBreezeObject<byte[]>()
{
Entity = new byte[] { 1, 2, 3, 4 },
Indexes = new List<DBreeze.Objects.DBreezeIndex>()
{
new DBreeze.Objects.DBreezeIndex(1, (long)1){ PrimaryIndex = true }
}
}, false); //Speed insert is off
//--> will be true because entity has changed
Console.Write(x1.EntityWasInserted);
tran.Commit();
}
from dbreeze.
To get inserted value:
//Inserting
byte[] ptr1 = null;
byte[] ptr2 = null;
using (var tran = engine.GetTransaction())
{
var x1 = tran.ObjectInsert<byte[]>("t1", new DBreeze.Objects.DBreezeObject<byte[]>()
{
Entity = new byte[] { 1, 2, 3 },
NewEntity = true,
Indexes = new List<DBreeze.Objects.DBreezeIndex>()
{
new DBreeze.Objects.DBreezeIndex(1, (long)1){ PrimaryIndex = true }
}
});
ptr1 = x1.PtrToObject;
x1 = tran.ObjectInsert<byte[]>("t1", new DBreeze.Objects.DBreezeObject<byte[]>()
{
Entity = new byte[] { 2, 6, 3 },
NewEntity = true,
Indexes = new List<DBreeze.Objects.DBreezeIndex>()
{
new DBreeze.Objects.DBreezeIndex(1, (long)2){ PrimaryIndex = true }
}
});
ptr2 = x1.PtrToObject;
tran.Commit();
}
//Getting
using (var tran = engine.GetTransaction())
{
//Variant 1 via index
var exp = tran.Select<byte[], byte[]>("t1", 1.ToIndex((long)1))
.ObjectGet<byte[]>();
//via pointer
var do1 = tran.ObjectGetByFixedAddress<byte[]>("t1", ptr1);
Console.WriteLine(do1.Entity.ToBytesString());
do1 = tran.ObjectGetByFixedAddress<byte[]>("t1", ptr2);
Console.WriteLine(do1.Entity.ToBytesString());
}
from dbreeze.
SelectDirect
byte[] ptr1 = null;
using (var tran = engine.GetTransaction())
{
tran.Insert<int, int>("t2", 1, 1, out ptr1);
tran.Commit();
}
using (var tran = engine.GetTransaction())
{
var row = tran.SelectDirect<int, int>("t2", ptr1);
Console.WriteLine(row.Exists); //->true
//row = tran.SelectDirect<int, int>("t2", new byte[] { 5,6,7}); //error non-existing
row = tran.SelectDirect<int, int>("t2", null); //ok
Console.WriteLine(row.Exists); //->false
}
from dbreeze.
Related Issues (20)
- Why duplicated projects? HOT 5
- Guide on how to fail-over with Raft and DBreeze HOT 10
- TextSearch bug HOT 6
- Getting "Getting table "@utCoins" from the schema failed!" when calling Technical_SetTable_OverwriteIsNotAllowed HOT 2
- DBreeze sorts by ID HOT 4
- DBreeze.Exceptions.DBreezeException: Creation of the database folder failed! ---> DBreeze.Exceptions.DBreezeException: Database is not operable, please find out the problem and restart the engine! FSR INIT FAILED HOT 5
- What's wrong with transactions? HOT 4
- Multiple DBreezeEngine instances to the same db files HOT 1
- Custom Serializator for Biser? HOT 4
- Biser Objectifies classes using different namespace than DBreeze's version HOT 6
- Text Search of items < minimum size not possible? HOT 4
- Count of documents ids 0 with data being in the table HOT 3
- .net core 5 HOT 4
- Serialize/Deserialize should not be static
- Reading from multiple tables at once and returning sorted results HOT 2
- TextSearch Tables still contains internal/external references, after using TextRemoveAll HOT 5
- RemoveSession is not called on "DBreeze.Exceptions.DBreezeException: One transaction can be used from one thread only!" HOT 1
- What happens to Old DataBlocks? HOT 7
- Memory mode insert slower than writes on disk HOT 1
- Database insert speed HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dbreeze.