I have a model on a single postgres database that is used by two processes.

using the following code code I am getting duplicate keys(an exception is being thrown) for Event when Events are created by the two processes.

[HierarchyRoot]
    public class Event : Entity {
        [Field, Key]
        public long Id { get; private set; }

Does your default key generator not uses sequences.

I am using your do40test database generated by the samples for testing my simple application and assumed because it created a Int64-Generator sequence it would use this.

Tony


Updated at 11.11.2009 16:16:36

If required I can send you the vs2008 solution zipped.


Updated at 11.11.2009 16:52:27

will send, the exception is:

{"ERROR: 23505: duplicate key value violates unique constraint \"PK_Event\""} "INSERT INTO \"public\".\"Event\" (\"Id\", \"TypeId\", \"ApplicationName\", \"Topic.Id\", \"args\") VALUES (12, 101, 'App2', 1, '\\000\\001\\000\\000\\000\\377\\377\\377\\377\\001\\000\\000\\000\\000\\000\\000\\000\\004\\001\\000\\000\\000\\020\\123\\171\\163\\164\\145\\155\\056\\105\\166\\145\\156\\164\\101\\162\\147\\163\\000\\000\\000\\000\\013')" at Npgsql.NpgsqlConnector.CheckErrors() at Npgsql.NpgsqlConnector.CheckErrorsAndNotifications() at Npgsql.NpgsqlCommand.ExecuteCommand() at Npgsql.NpgsqlCommand.ExecuteNonQuery() at Xtensive.Storage.Providers.Sql.Driver.ExecuteNonQuery(Session session, DbCommand command) in c:\TeamCity\buildAgent\work\6a5d81309423096e\Xtensive.Storage\Xtensive.Storage.Providers.Sql\Driver.Operations.cs:line 108


Updated at 11.11.2009 22:22:30

Not using TeamCity, never heard of it until your post.

Ok you have triggered a thought, I duplicated the process from the first process and may have left it set to recreate the domain, hence hence the problem with duplicate and cached keys. Code is at work, will check tomorrow, but suspect its my fault.

Sorry for wasting your time. Tony

This thread was imported from our support forum. The original discussion may contain more detailed answer.

asked Nov 11 '09 at 15:19

Tony's gravatar image

Tony
53262628

Hello Tony,

Default key generator for PostgreSql must definitely use appropriate sequence. I'm going to investigate this issue asap.

(Nov 11 '09 at 15:19) Dmitri Maximov Dmitri%20Maximov's gravatar image

Yes. please. Send it to support@x-tensive.com.

Thanks

(Nov 11 '09 at 15:19) Dmitri Maximov Dmitri%20Maximov's gravatar image

One Answer:

Dmitri Maximov (Xtensive) wrote:

Tony, I made some tests. My approach was rather straightforward: I launched 2 instances of Visual Studio with the same unit test, which contains bulk inserts, on the same PostgreSql database. Both domains were being built in various modes: Validate, Perform and PerformSafely (Recreate mode doesn't make sense as generators are recreated in it). But I failed to reproduce the reported issue.

I hope that your sample will help to do it.

Thanks.


Alex (Xtensive) wrote:

I noticed you use TeamCity - is it possible that two different projects there use the same database? If so, first process may e.g. build the domain, do something and sleep (w/o keeping open transactions) while the second one will recreate its database and generators. Thus when the first one will wake up, it might try to use keys from its cached sequence, but now they may conflict with the existing ones.

Note that "sleeping" may be caused by some intermediate test in sequence that does not involve transactions at all, or do something, that isn't related to DO4.

That's just an assumption. I don't see other possibilities allowing this to happen except this one or bugs in DO4.

answered Nov 11 '09 at 16:52

Editor's gravatar image

Editor
46156156157

Not using TeamCity, never heard of it until your post.

That's my mistake: I noticed it in stack trace, but that was our own part of it ;)

(Nov 11 '09 at 16:52) Alex Yakunin Alex%20Yakunin's gravatar image

Tony wrote: Was my fault.

Tony

(Nov 11 '09 at 16:52) Editor Editor's gravatar image

Ok - thanks ;)

(Nov 11 '09 at 16:52) Alex Yakunin Alex%20Yakunin's gravatar image
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!
toggle preview

powered by OSQA