Morphium v6.x Update: 13 Releases at a Glance

info

date: 2026-02-23 21:08:56

tags: Java Morphium programming MongoDB open_source

category: morphium

creator Stephan Bösebeck

logged in

ADMIN


Morphium v6.x Update: 13 Releases at a Glance

Morphium v6.0.1 to v6.1.8 - What's New?

A lot has happened since the release of Morphium v6.0.0. Across 13 releases, we've improved the Java MongoDB library in many areas - from fundamental architectural changes to performance optimizations and a much more stable connection pool. Here's an overview of the most important changes.

Null Handling Completely Reworked (v6.0.1)

Null handling in Morphium had grown organically and wasn't particularly intuitive. With v6.0.1, we changed this fundamentally:

  • New default behavior: Null values are now stored as explicit null in the database - just like Hibernate and JPA do it.
  • New @IgnoreNullFromDB annotation: If you need the old behavior, you can selectively protect fields from null contamination.
  • @UseIfNull deprecated: The old annotation with its confusing inverted logic is deprecated but still functional.

This is a breaking change, but one that makes the API much more consistent.

MorphiumServer: From Test Helper to Mini-MongoDB (v6.1.0)

MorphiumServer made the biggest leap. What started as a simple in-memory replacement for tests is now a real alternative for development and test environments:

Replica Set Support

  • Automatic primary election: A Raft-inspired election protocol selects the primary based on configurable priorities.
  • Automatic failover: If the primary goes down, a new one is elected automatically.
  • Data replication: Changes are replicated to secondaries via change streams - including drop, replace, and rename operations.

SSL/TLS

MorphiumServer now accepts encrypted connections: server.setSslEnabled(true); server.setSslContext(sslContext);

Persistence

Data can now be written to disk and restored on startup: java -jar morphium-server-cli.jar --dump-dir /data --dump-interval 60

More Server Improvements

  • Standalone CLI JAR (morphium-server-cli.jar)
  • Netty-based wire protocol handler for better performance
  • listDatabases support, proper killCursors handling
  • Write concern handling with partial replica sets

InMemoryDriver: Faster and More Feature-Rich

Performance Optimizations

The InMemoryDriver's performance has been significantly improved:

  • Parallelism: Removed global synchronization on sendCommand() - operations on different collections now run in parallel.
  • Smart deep copies: Documents are only copied after a successful query match, with projection-aware copying.
  • $in operator: From O(n*m) to O(n+m) using HashSet lookups.
  • TTL handling: Collections without TTL indexes now have zero overhead.
  • Index lookups: Simple equality queries use Objects.equals() instead of full matchesQuery() evaluation.

New Features

  • Tailable cursors: InMemoryDriver now supports tailable queries.
  • Shared databases: Multiple Morphium instances can share the same in-memory database.
  • $text queries: MongoDB-compatible full-text search with phrase search and negation.

Connection Pool: Finally Stable (v6.1.4 - v6.1.8)

The connection pool was a persistent pain point across multiple releases. Starting with v6.1.4, we systematically fixed all known issues:

Counter Drift Fixed

The main problem: The borrowedConnections counter drifted, making the pool appear "full" even though all connections had been returned. Root causes:

  • Hostname case mismatch: MongoDB reports hostnames differently than configured in the seed (SERV-MSG1 vs serv-msg1). The releaseConnection() couldn't find the connection. Fix: All hostname operations now normalize to lowercase.
  • Topology changes: When a host left the replica set, borrowed connections weren't decremented. Fix: borrowedFromHost tracking for correct attribution.
  • Double-decrement race: Under concurrency, the same counter could be decremented twice. Fix: Guard against double-decrement.

Connection Leaks Closed

  • Heartbeat connections weren't returned on exceptions.
  • ChangeStreamMonitor didn't release connections when the watch had no connection object.
  • Zombie connections when socket closed before cleanup.

Concurrency Improvements

  • Replaced synchronized + wait with ReentrantLock + Condition.
  • Replaced add() with offer(timeout) on connection queues - no more deadlocks.
  • Parallel connection creation (up to 10 virtual threads) for burst scenarios.

ChangeStreamMonitor: Self-Healing (v6.1.4+)

  • Retry instead of crash: On "connection closed", the connection is rebuilt instead of stopping the monitor.
  • Resume tokens: The monitor remembers the last token and resumes from there after reconnect - no more duplicate or missed events.
  • ChangeStreamHistoryLost: Stale resume tokens are discarded, the stream starts fresh.
  • Lock TTL bug: Messages without timeout had TTL=0, causing locks to be deleted immediately. Fix: 7-day fallback TTL.

Messaging Stability

  • Sending messages to self now works correctly.
  • MultiCollectionMessaging respects setUseChangeStream(false) for direct messages too.
  • Sequence generator handles stale locks better.
  • Various deadlocks in messaging and server components fixed.

Jackson Removed (Post v6.1.8)

Jackson has been removed as a dependency to avoid dependency conflicts. JSON serialization now runs entirely through Morphium's own ObjectMapper. A follow-up fix ensures that List properties (like hostSeed) are correctly serialized during roundtrips.

Test Infrastructure Completely Modernized

  • Multi-driver tests: 72 test classes migrated to MultiDriverTestBase, 356+ tests as @ParameterizedTest.
  • Backend selection: runtests.sh supports --driver inmem|pooled|all and --morphium-server.
  • Better isolation: Each test only cleans up its own database.
  • Skip/limit alignment: Consistent behavior across all drivers.

Conclusion

From v6.0.0 to v6.1.8, Morphium has improved in practically every area. MorphiumServer has grown from a simple test mock into a real lightweight alternative, the connection pool is finally reliable, and InMemoryDriver performance makes unit tests significantly faster.

Next up: Even fewer external dependencies and continued progress toward production readiness for MorphiumServer.