More

Upgrading

What an application written for an earlier XOD 2.x must change or check before it moves to a later version.

This page is a checklist for moving an application to a later XOD version. Start at the section for the version you have and work up. Each item links to the page that explains it. Back up the database folder before the first open with the new version, and close every context of the old version first.

Upgrading from 2.1.0 to 2.2.0

The file format is compatible: 2.2.0 opens 2.1.0 databases directly (scanning every page once at the first open to check for duplicate row codes), and 2.1.0 reads databases written with stored map comparers under its default comparers. What an application written for 2.1.0 must check before it moves to 2.2.0.

Code that no longer builds cleanly

  • [Inherited], LazyLoadFilter and ReservedPropertyType are obsolete (warning CS0618, an error in a build that treats warnings as errors). They did nothing (see Attributes and XodContext API).

What can now throw

  • A map property XOD can’t construct or whose keys or values aren’t scalars (Dictionary<string, object>, a map of a class, interface or Uri, or a map type with no parameterless constructor, entries constructor or known factory) is refused when its class is first used. A 2.0.x row written for an IDictionary<K, V> property throws DatabaseFileException naming the row and property (SQL reads NULL with warning XQ014) (see Supported types).
  • An object property holding a collection, string, number, date, Guid or struct (without [GenericTypeProperty] naming the full type), or a List<object> holding a collection, string, number or struct, is refused when written and in a query by example.
  • An undefined StorageFormat throws ArgumentOutOfRangeException in a context, XodMigrator and xod convert (see DatabaseOptions).
  • A missing page file named by a table, or an index entry whose row isn’t on its page, throws DatabaseFileException instead of skipping rows silently (see Storage).
  • Inserting a parent with a child another parent lists throws ReservedChildException (see Relationships).
  • Inside a BeforeAction or AfterAction handler, Flush, ClearCache/ClearCaches and GetStatistics throw InvalidOperationException in buffered mode or a transaction, and Commit/Rollback throw TransactionException in every mode (see Events).
  • Reading a map whose stored culture is unavailable on the reading machine (including globalization-invariant mode) throws DatabaseFileException naming the culture.

Behaviour to check

  • A derived class inherits XOD attributes from virtual base properties it overrides ([PrimaryKey], [UniqueKey], [Property], [NotMapped], relations). Check derived classes that relied on base attributes being ignored on overrides (see Modelling data).
  • A Guid? Id gets a new Guid when inserted null (autonumber by convention). Existing rows keep their stored key (see Primary keys).
  • In DurabilityMode.Buffered, InsertRange, Delete and DeleteWhere wait for Flush(), as every other buffered write does, and every failed write in buffered mode or a transaction leaves nothing of itself (see Transactions and durability).
  • Self-referencing and mutually-referencing [ForeignKey] relations follow Cascade = Update and Cascade = Delete (see Relationships).
  • String-keyed built-in maps store and restore their StringComparer, and sorted string maps without a stored comparer read back in ordinal order rather than the reading machine’s culture order (see Supported types).
  • The first open of an existing database reads every page once to check for duplicate row codes, recodes any it finds (rebuilding indexes if needed), and records that check in the database file.

Upgrading from 2.0.3 to 2.1.0

The file format is the same. What an application written for 2.0.3 must check before it moves to 2.1.0.

What can now throw

  • A key part at its type’s default. A row whose key isn’t an autonumber is refused with MissingPrimaryKeyValueException when a key part is 0, false, an enum’s first member, an empty Guid, or an empty or null string. So is an update by such a key, and an update or delete by an example that sets some key parts and not others. A row 2.0.3 stored that way can’t be updated or deleted by its key: remove it with DeleteWhere (see Models).
  • A type XOD can’t store or read back. A class with a property of Int128, Half, BigInteger, nint, a tuple or a struct of your own, or a collection a List<T> can’t be assigned to (class Notes : List<Note>, HashSet<T>, ArrayList), is refused with XodException when it is first used. Mark the property [NotMapped] or change its type. 2.0.3 stored these and read them back empty or at their default.
  • A write inside a read on the same thread, such as in a query’s predicate or while its results are enumerated, throws XodException, for every table. Make the write after the read (see Writing).
  • Inside a trigger, BeginTransaction throws TransactionException, and setting, changing or removing the password throws InvalidOperationException.

Behaviour to check

  • A transaction belongs to the code that began it. Other threads’ reads and writes wait for it to end, up to TransactionTimeoutMs, and no longer see or join its writes. Keep transactions short, and begin one where its work is done (see Transactions).
  • Writes are made one at a time, for every table.
  • InsertRange, DeleteWhere and DropAll are each one write. Outside a transaction, with the default durability, one refused item leaves none of it done. DeleteWhere returns the number of rows it deleted.
  • A parent’s update writes its [Children] and the relations declared Cascade = CascadeOptions.Update, and no others. A plain list or reference of objects with a key only links them. Declare [Property(Cascade = CascadeOptions.Update)] on it, or update those objects yourself (see Relationships).
  • Deleting a row deletes its children and its plain lists of objects without a key, with their triggers. An object property deletes the row of a keyed type it holds only with Cascade = Delete. Clearing a Cascade = Delete reference in an update deletes its row.
  • A child without a key is written again at each update of its parent: its old row is deleted and a new one inserted, with their triggers. Give it a key to have it updated in place.
  • The obsolete CryptoHelper.EncryptProperty and DecryptProperty, given a passphrase, take about 25 ms a call. A [Crypto(AES256)] property is encrypted by the database itself.
  • A password-protected database written by 2.0.x reads each file a little slower, once per context, until the file is written again.

Upgrading from 2.0.2 to 2.0.3

What an application written for 2.0.2 must check before it moves to 2.0.3.

One context per database

  • A database is open in one context at a time. Keep one XodContext per database for the life of the application (a singleton, not one per request or per scope) and dispose it. A second open, in the same process or another, waits LockRetryTimeoutMs, then throws DatabaseLockedException. A context never disposed keeps the database until the garbage collector finalizes it (see Processes).
  • LockDatabase no longer changes anything. Code that sets it still compiles.
  • The command-line tool (xod stats, xod query and the others) is refused while an application has the database open (see Command-line tool).

Before the first open

  • XOD 2.0.2 and 2.0.3 keep each other out. 2.0.2 holds the lock files shared and 2.0.3 alone, so whichever opens second is refused with DatabaseLockedException. XOD 2.0.0 and 2.0.1 take no lock unless LockDatabase is set: don’t run them beside 2.0.3.
  • Leave the lock files alone. xod.lock and app.xod.lock sit beside the database file and are never deleted, as in 2.0.2. A folder where they can’t be created or opened is opened for reading only, and nothing keeps a writer out beside such a reader (see Read-only folders).
  • Where the file system gives no lock (an NFS client, for example), every open is refused, since nothing would keep a second context out. On Linux or macOS, setting DOTNET_SYSTEM_IO_DISABLEFILELOCKING=1 opens it, taken as saying nothing else opens the database.
  • A context that can only read the folder, with the lock files there, holds the database too. A reader run by another user keeps the application’s open out until it closes.
  • A transaction no longer sets files aside. A .xdel file 2.0.2 left at a crash is put back by the next open (see What’s in the folder).

Code that no longer builds cleanly

  • XmlExtensions.ElementMatch is obsolete (warning CS0618, an error in a build that treats warnings as errors): XOD no longer matches rows by it (see XodContext API).

What can now throw

  • A second context’s open throws DatabaseLockedException, as above.
  • Secure, ChangePassword and Loose throw XodException over a .xdel file or a password change’s own files a crash left, as they do over a journal (see Adding, changing and removing the password).

Behaviour to check

  • Matching by example compares text exactly and numbers by value, with or without an index: Query by example, Update and Delete, and, with EnableIndexing = false, the primary-key and unique checks. Without an index, 2.0.2 compares text ignoring case, so code that relied on “alice” finding “Alice” gets nothing. Match the case, or query with a lambda (see Query many and Indexes).
  • Referenced objects are built afresh by every query: two queries give two instances of one customer. Code that compared them by reference, or relied on an unsaved change to one showing in the next query, needs changing (see Loading relationships).
  • A rollback writes nothing back, and a transaction’s deletes take effect at its commit (see Transactions).
  • The AES256 key is made when a database gets a secret: at its creation with a password or PropertyEncryptionKey, or by Secure, ChangePassword or Loose (see A key of the database’s own).
  • A database from XOD 1.x: an encrypted one opens with its password, and 1.x digests verify and are kept by an update (see Moving from XOD 1.x).

Upgrading from 2.0.0 or 2.0.1 to 2.0.2

What an application written for 2.0.0 or 2.0.1 must change or check before it moves to 2.0.2. Read Moving back to 2.0.0 or 2.0.1 before you rely on going back.

Code that no longer builds cleanly

  • IdentitySeed and IdentityIncrement are object, where 2.0.1 has dynamic. Code that reads them as a number (int seed = attribute.IdentitySeed;) needs a cast. They can now be set (see The Property attribute in full).
  • A subclass of [Property] that sets IdentitySeed or IdentityIncrement in its constructor (2.0.1’s only way to set them) still numbers a number property as before. On a Guid autonumber, 2.0.1 ignores them; 2.0.2 refuses the type with AutonumberSeedException when it is first used, even for a value of
    1. Don’t put such a subclass on a Guid (see The Property attribute in full).
  • Obsolete members give warning CS0618, an error in a build that treats warnings as errors:
    • XodSecurityService and IXodSecurityService: use Secure, ChangePassword and Loose on the context (see Passwords and encryption);
    • CryptoHelper.EncryptProperty and DecryptProperty, which use 2.0.1’s form of an AES256 value: [Crypto(CryptoMethod.AES256)] encrypts and decrypts the property itself (see Encrypting a property);
    • DatabaseOptions.EnableCompression, which never had an effect: use StorageFormat.Binary (see DatabaseOptions).

Property encryption

  • AES256 without a database password. XOD 2.0.2 won’t encrypt with the key built into the library. A database with no password and no DatabaseOptions.PropertyEncryptionKey refuses every insert or update that stores an AES256 value with SecurityException; reads still work, the values 2.0.1 wrote included. Set PropertyEncryptionKey (or a password) before the upgrade goes live (see A key of the database’s own).
  • Values 2.0.1 encrypted aren’t converted until their row is next written (see A key of the database’s own).
  • [Crypto] on a type that isn’t string, or on a property that is indexed, a unique key or a primary key, is refused when the type is first used, with CryptoDataTypeException or IndexDataTypeException. 2.0.1 ignores [Crypto] on other types and stores the plain value. Change the model first (see Attributes).
  • [Crypto] on a value stored as an attribute (ValuePosition.Attribute) is now applied, where 2.0.1 stores the value as written (see Attributes).
  • Changing or removing the password is refused with SecurityException when the database holds AES256 values 2.0.1 wrote under it and the change would leave them unreadable (see Adding, changing and removing the password).

Locks, processes and password changes

  • LockDatabase keeps out every other context, with LockDatabase or without: an open while a LockDatabase context or process has the database gets DatabaseLockedException, xod stats included. 2.0.1 keeps out only contexts that also set LockDatabase (see Processes and xod stats).
  • A password change needs the database to itself. Secure, ChangePassword and Loose are refused with XodException while another context or process has the database open, and with TransactionException inside a transaction. While a change runs, an open elsewhere gets DatabaseLockedException (see Adding, changing and removing the password).
  • Contexts opened at once on a new database. The open that creates it holds the folder alone until its database file is written; another open meanwhile waits up to LockRetryTimeoutMs, then gets DatabaseLockedException. 2.0.1 lets both go on. Open the first context before the others, or set LockRetryTimeoutMs (see One database per folder).
  • Dispose every context. One left to the garbage collector holds the lock file, and keeps out LockDatabase opens and password changes until it is finalized (see Processes).
  • Leave the new files alone. The database’s lock file now stays after the close, and so does the folder’s, xod.lock; the folder can also hold .xidxdirty, .xdel, .xpwlog and .xpwnew files. Don’t delete them while the database is open (see What’s in the folder).
  • A folder XOD can’t write opens for reading only when the lock file can’t be opened or created; with LockDatabase, the open throws UnauthorizedAccessException (see Read-only folders).

Files, folders and conversion

  • One database per folder. Opening a folder that holds more than one database file, or a path naming a new database file beside an existing one, is refused with XodException (see One database per folder).
  • The migrator needs an empty target. XodMigrator.ConvertDatabase and xod convert refuse a target folder that holds anything, and a source that a context or process has open (see Converting between formats).
  • The format comes from the database. Without StorageFormat set, a context writes a database in the format its database file records, where 2.0.1 writes the one the extension or the options pick (XML for options that don’t set it). So a .xod database converted to JSON or binary in place is now written in JSON or binary, and a .xodj or .xodb database opened with options that don’t set a format is written in the format it records, not in XML (see Choosing a format).
  • A new database in a folder named .json or .bin is XML. Set StorageFormat to create it in JSON or binary. A database 2.0.1 created that way keeps its format (see Choosing a format).
  • Table files gain a <Schema> element at the next write to each table, so a database folder kept in version control shows each .xtab file changed once (see What’s in the folder).
  • Indexes are rebuilt from the pages the first time each is needed, so the first queries after the upgrade take longer (see Moving back to 2.0.0 or 2.0.1).

Behaviour to check

  • Writes from inside a read that need a lock the read holds back throw XodException, where 2.0.1 throws LockRecursionException. Code that catches the latter needs changing (see Writes from many threads).
  • Values read back as written: an empty string comes back as "", and a null as null, where 2.0.1 can return null or what a new instance holds (see Values read back as written).
  • Maps and lists read back as written: a dictionary’s null value comes back as null, where 2.0.1 gives ""; a list or array keeps its null items, which 2.0.1 drops; and an empty dictionary comes back empty, where 2.0.1 gives null (see Values read back as written).
  • Autonumbers aren’t handed out again after a delete and a reopen, and an update that leaves an autonumber at 0 keeps the row’s number (see Primary keys and Update).
  • A failed write behaves differently: a statement that fails removes the rows it created, a handler that throws makes the write fail, and a failed write is kept: an Insert is taken back, so it can be retried, but an InsertRange, Update or Delete that threw is still made by the next flush (see Writes outside a transaction and Durability).
  • xod output sent to a file or a pipe is UTF-8, where 2.0.1 writes it in the console’s code page. A script that reads it in another encoding needs changing (see Command-line tool).

Moving back to 2.0.0 or 2.0.1

Plan for these before a database written by 2.0.2 or later goes back to 2.0.0 or 2.0.1:

  • A page with a control character in any value is one 2.0.1 can’t read at all: every read of that page fails with DatabaseFileException.
  • An AES256 value 2.0.2 wrote reads in 2.0.1 as its stored text, and if 2.0.1 saves the row, the value is lost.
  • Don’t run both at once. 2.0.1 takes no lock without LockDatabase, and deletes the lock file at the close with it (see Processes).
  • Empty and null values 2.0.2 wrote read back differently in 2.0.1, and 2.0.1 rebuilds the indexes 2.0.2 wrote the first time it needs them.
  • A row that holds a list of a nullable type (List<int?>), or an empty map of a type other than Dictionary<K, V>, can’t be read by 2.0.1.

Source on GitHub · Report a problem with this page