private void LoadColumnInformation()
 {
     _columnsInformation = new ColumnsInformation();
     _instance.WithDatabase(_database, (session, dbid) =>
     {
         using (var table = new Table(session, dbid, "subqueues", OpenTableGrbit.ReadOnly))
         {
             _columnsInformation.SubqueuesColumns = Api.GetColumnDictionary(session, table);
         }
         using (var table = new Table(session, dbid, "outgoing_history", OpenTableGrbit.ReadOnly))
         {
             _columnsInformation.OutgoingHistoryColumns = Api.GetColumnDictionary(session, table);
         }
         using (var table = new Table(session, dbid, "outgoing", OpenTableGrbit.ReadOnly))
         {
             _columnsInformation.OutgoingColumns = Api.GetColumnDictionary(session, table);
         }
         using (var table = new Table(session, dbid, "recovery", OpenTableGrbit.ReadOnly))
         {
             _columnsInformation.RecoveryColumns = Api.GetColumnDictionary(session, table);
         }
         using (var table = new Table(session, dbid, "transactions", OpenTableGrbit.ReadOnly))
         {
             _columnsInformation.TxsColumns = Api.GetColumnDictionary(session, table);
         }
         using (var table = new Table(session, dbid, "queues", OpenTableGrbit.ReadOnly))
         {
             _columnsInformation.QueuesColumns = Api.GetColumnDictionary(session, table);
         }
         using (var table = new Table(session, dbid, "recveived_msgs", OpenTableGrbit.ReadOnly))
         {
             _columnsInformation.RecveivedMsgsColumns = Api.GetColumnDictionary(session, table);
         }
     });
 }
Example #2
0
 private void SetIdFromDb()
 {
     try
     {
         instance.WithDatabase(database, (session, dbid) =>
         {
             using (var details = new Table(session, dbid, "details", OpenTableGrbit.ReadOnly))
             {
                 Api.JetMove(session, details, JET_Move.First, MoveGrbit.None);
                 var columnids     = Api.GetColumnDictionary(session, details);
                 var column        = Api.RetrieveColumn(session, details, columnids["id"]);
                 Id                = new Guid(column);
                 var schemaVersion = Api.RetrieveColumnAsString(session, details, columnids["schema_version"]);
                 if (schemaVersion != SchemaCreator.SchemaVersion)
                 {
                     throw new InvalidOperationException("The version on disk (" + schemaVersion + ") is different that the version supported by this library: " + SchemaCreator.SchemaVersion + Environment.NewLine +
                                                         "You need to migrate the disk version to the library version, alternatively, if the data isn't important, you can delete the file and it will be re-created (with no data) with the library version.");
                 }
             }
         });
     }
     catch (Exception e)
     {
         throw new InvalidOperationException("Could not read db details from disk. It is likely that there is a version difference between the library and the db on the disk." + Environment.NewLine +
                                             "You need to migrate the disk version to the library version, alternatively, if the data isn't important, you can delete the file and it will be re-created (with no data) with the library version.", e);
     }
 }
Example #3
0
        public Guid ChangeId()
        {
            Guid newId = Guid.NewGuid();

            instance.WithDatabase(database, (session, dbid) =>
            {
                using (var details = new Table(session, dbid, "details", OpenTableGrbit.None))
                {
                    Api.JetMove(session, details, JET_Move.First, MoveGrbit.None);
                    var columnids = Api.GetColumnDictionary(session, details);
                    using (var update = new Update(session, details, JET_prep.Replace))
                    {
                        Api.SetColumn(session, details, columnids["id"], newId.ToByteArray());
                        update.Save();
                    }
                }
            });
            Id = newId;
            return(newId);
        }
 private void SetIdFromDb()
 {
     try
     {
         instance.WithDatabase(database, (session, dbid) =>
         {
             using (var details = new Table(session, dbid, "details", OpenTableGrbit.ReadOnly))
             {
                 Api.JetMove(session, details, JET_Move.First, MoveGrbit.None);
                 var columnids     = Api.GetColumnDictionary(session, details);
                 var column        = Api.RetrieveColumn(session, details, columnids["id"]);
                 Id                = new Guid(column);
                 var schemaVersion = Api.RetrieveColumnAsString(session, details, columnids["schema_version"]);
                 if (schemaVersion == SchemaCreator.SchemaVersion)
                 {
                     return;
                 }
                 do
                 {
                     var updater = Updaters.FirstOrDefault(update => update.Value.FromSchemaVersion == schemaVersion);
                     if (updater == null)
                     {
                         throw new InvalidOperationException(string.Format("The version on disk ({0}) is different that the version supported by this library: {1}{2}You need to migrate the disk version to the library version, alternatively, if the data isn't important, you can delete the file and it will be re-created (with no data) with the library version.", schemaVersion, SchemaCreator.SchemaVersion, Environment.NewLine));
                     }
                     updater.Value.Init(generator);
                     updater.Value.Update(session, dbid);
                     schemaVersion = Api.RetrieveColumnAsString(session, details, columnids["schema_version"]);
                 } while (schemaVersion != SchemaCreator.SchemaVersion);
             }
         });
     }
     catch (Exception e)
     {
         throw new InvalidOperationException(
                   "Could not read db details from disk. It is likely that there is a version difference between the library and the db on the disk." +
                   Environment.NewLine +
                   "You need to migrate the disk version to the library version, alternatively, if the data isn't important, you can delete the file and it will be re-created (with no data) with the library version.",
                   e);
     }
 }
Example #5
0
        private void SetIdFromDb()
        {
            try
            {
                instance.WithDatabase(database, (session, dbid) =>
                {
                    using (var details = new Table(session, dbid, "details", OpenTableGrbit.ReadOnly))
                    {
                        Api.JetMove(session, details, JET_Move.First, MoveGrbit.None);
                        var columnids     = Api.GetColumnDictionary(session, details);
                        var column        = Api.RetrieveColumn(session, details, columnids["id"]);
                        Id                = new Guid(column);
                        var schemaVersion = Api.RetrieveColumnAsString(session, details,
                                                                       columnids["schema_version"]);
                        if (schemaVersion == SchemaCreator.SchemaVersion)
                        {
                            return;
                        }

                        using (var ticker = new OutputTicker(TimeSpan.FromSeconds(3), () =>
                        {
                            log.Info(".");
                            Console.Write(".");
                        }, null, () =>
                        {
                            log.Info("OK");
                            Console.Write("OK");
                            Console.WriteLine();
                        }))
                        {
                            bool lockTaken = false;
                            try
                            {
                                Monitor.TryEnter(UpdateLocker, TimeSpan.FromSeconds(15), ref lockTaken);
                                if (lockTaken == false)
                                {
                                    throw new TimeoutException("Could not take upgrade lock after 15 seconds, probably another database is upgrading itself and we can't interrupt it midway. Please try again later");
                                }

                                do
                                {
                                    var updater = Updaters.FirstOrDefault(update => update.Value.FromSchemaVersion == schemaVersion);
                                    if (updater == null)
                                    {
                                        throw new InvalidOperationException(
                                            string.Format(
                                                "The version on disk ({0}) is different that the version supported by this library: {1}{2}You need to migrate the disk version to the library version, alternatively, if the data isn't important, you can delete the file and it will be re-created (with no data) with the library version.",
                                                schemaVersion, SchemaCreator.SchemaVersion, Environment.NewLine));
                                    }

                                    log.Info("Updating schema from version {0}: ", schemaVersion);
                                    Console.WriteLine("Updating schema from version {0}: ", schemaVersion);

                                    ticker.Start();

                                    updater.Value.Init(configuration);
                                    updater.Value.Update(session, dbid, Output);
                                    schemaVersion = Api.RetrieveColumnAsString(session, details, columnids["schema_version"]);

                                    ticker.Stop();
                                } while (schemaVersion != SchemaCreator.SchemaVersion);
                            }
                            finally
                            {
                                if (lockTaken)
                                {
                                    Monitor.Exit(UpdateLocker);
                                }
                            }
                        }
                    }
                });
            }
            catch (EsentVersionStoreOutOfMemoryException esentOutOfMemoryException)
            {
                var message = "Schema Update Process for " + database + " Failed due to Esent Out Of Memory Exception!" +
                              Environment.NewLine +
                              "This might be caused by exceptionally large files, Consider enlarging the value of Raven/Esent/MaxVerPages (default:512)";
                log.Error(message);

                Console.WriteLine(message);
                throw new InvalidOperationException(message, esentOutOfMemoryException);
            }
            catch (Exception e)
            {
                var message = "Could not read db details from disk. It is likely that there is a version difference between the library and the db on the disk." +
                              Environment.NewLine +
                              "You need to migrate the disk version to the library version, alternatively, if the data isn't important, you can delete the file and it will be re-created (with no data) with the library version.";
                log.Error(message);
                Console.WriteLine(message);
                throw new InvalidOperationException(
                          message,
                          e);
            }
        }