yangtools.git
4 years agoRework AbstractNormalizedNodePruner
Robert Varga [Tue, 14 May 2019 08:15:19 +0000 (10:15 +0200)]
Rework AbstractNormalizedNodePruner

This refactors NormalizedNodePruner to use
ReusableImmutableNormalizedNodeStreamWriter for creation of the
actual NormalizedNode tree.

It simplifies the implementation and allows the reuse of minor
optimizations like LeafInterner.

JIRA: CONTROLLER-1889
Change-Id: I93bd00bcff13245d808f7adf6122a6c20156e9fd
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
4 years agoSwitch default stream output to Sodium SR1
Robert Varga [Wed, 25 Sep 2019 06:01:47 +0000 (08:01 +0200)]
Switch default stream output to Sodium SR1

This flips the switch and uses Sodium SR1 format for all unversioned
users. Also updates tests to reflect new expected stream sizes.

JIRA: CONTROLLER-1919
Change-Id: I9973bb93f469c1b59533ce580c795cd30c9edda4
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
4 years agoEliminate reference to YangInstanceIdentifier.EMPTY
Robert Varga [Wed, 25 Sep 2019 14:45:57 +0000 (16:45 +0200)]
Eliminate reference to YangInstanceIdentifier.EMPTY

This constant has been removed, migrate to its replacement.

Change-Id: I0937b4602552ec8101132319889bc92e63de06cb
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
4 years agoAdd Magnesium stream version
Robert Varga [Wed, 25 Sep 2019 06:07:50 +0000 (08:07 +0200)]
Add Magnesium stream version

This is a variant of Sodium SR1 streaming format, which does not
allow presence of BigInteger tokens, as those values are superseded
by Uint64.

JIRA: CONTROLLER-1919
Change-Id: I1dc5c7376bf1ecf105e965e42d74806ed99ab9b1
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
4 years agoAdd LithiumSR1 input/output support
Robert Varga [Mon, 9 Sep 2019 08:29:57 +0000 (10:29 +0200)]
Add LithiumSR1 input/output support

This is a code drop of both DataInput and DataOutput for Sodium SR1
streaming format. It uses its own dedicated tokes, along with quite
a few of stateful encoding rules.

Where Lithium did encoding did not perform any look-behind except
for LeafSetEntryNodes and only maintained simple coding tables,
this coder maintains simple 'parent' state tracking.

While the state tracking is not mandated on the encoder side, some
amount of tracking is required in the decoder side to provide full
coverage of coding constructs.

Two examples of this are:
- parent QName references, which are expanded to cover not only
  LeafSet/LeafSetEntry, but also UnkeyedList/UnkeyedListEntry
  and most importantly Map/MapEntry pairs
- Map/MapEntry tracking is also important for coding leaf nodes
  which represent keys -- in those cases emitting the leaf value
  is superfluous, as it can be looked up from MapEntry's predicates

Also this state tracking is maintained on-stack, thus making issues
related with it nigh impossible (unlike the Lithium LeafSetEntry
bugs).

JIRA: CONTROLLER-1919
Change-Id: I5fcf85a76750301cd3f8bcbd505baa0f95397cb5
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
4 years agoAdd Magnesium encoding tokens
Robert Varga [Fri, 20 Sep 2019 08:07:10 +0000 (10:07 +0200)]
Add Magnesium encoding tokens

Changes to how uint8/16/32/64 types are mapped results in the need
to transfer the new value types. These represent 4 brand new tokens,
which need to be handled.

One option would be to fork NeonSR2 and modify it, somehow dealing
with value lookups (i.e. Uint8 is not valid in SR2 stream, but tokens
are shared across Lithium/NeonSR).

Another option is to create a streaming format from scratch, coming
up with a completely new family of tokens and encoding rules. This
is attractive, as both current formats have three deficiencies:

1) they encode MapEntry key values twice, once in the leaf itself
   and once in the entry's NodeIdentifierWithPredicates
2) they are '0-happy', i.e. they do not recognize that integer codes
   and sizes are typically much smaller than the 4-byte range and thus
   much of the stream is just small ints encoded as 4 bytes
3) while they are simple and straighforward, they also end up wasting
   bits -- the four token families (codes, value types, node types,
   path argument types) each have at most 15 distinct values, and
   hence the bytes used to transmit them have 4 empty bits (or more)

Hence we take the other option and design a streaming format with
brand new tokens, which are structured to carry as much more
information per byte.

This is done by combining 'type' information with forward coding
hints, for example:

- a Boolean leaf value would previously require 2 bytes:
    (byte)    ValueTypes.BOOL_TYPE
    (byte)    true/falseIn the new tokens
  whereas new tokens express this in one byte:
    (byte)    LeafValue.BOOLEAN_{FALSE,TRUE}
- a byte[5] value would require 10 bytes to encode:
    (byte)    ValueTypes.BINARY_TYPE
    (int)     length
    (5 bytes) bytes
  whereas new tokens express this in 6 bytes:
    (byte)    ValueTypes.BINARY_0 + 5 (works up to 127)
    (5 bytes) bytes

A similar approach is taken when encoding NormalizedNode types. Here
we recognize there are only 14 node types (currently) and hence we
can provide up to 4 additional bits for information about how the
node's identifier is encoded.

For PathArguments, we also use separate coding, where the format
is flexible based on the 4 types on identifiers there are, each
having slightly different format. Most notable here is the integration
of QName reference coding (for normal PathArguments) and integrated
set size coding (for AugmentationIdentifiers).

This this patch adds just the token definitions, along with basic
documentation and version declaration.

JIRA: CONTROLLER-1919
Change-Id: I9f6f58a7cb77d9d98c46e13b8dc6955c8e3c0737
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
4 years agoRework PathArgumentTypes lookup
Robert Varga [Fri, 30 Aug 2019 09:08:37 +0000 (11:08 +0200)]
Rework PathArgumentTypes lookup

This lookup relying on final methods, which is not a correct
assumption, with NodeIdentifierWithPredicates having at least two
properly-hidden implementations.

Rework the lookup in terms of instanceof checks, which saves a table
lookup and unboxing operation.

Change-Id: Ia6b272715d19e432e7e0839b6294035e12b1d293
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
4 years agoMove Neon SR2 tokens into its own class
Robert Varga [Fri, 20 Sep 2019 17:42:15 +0000 (19:42 +0200)]
Move Neon SR2 tokens into its own class

Same as with base Lithium tokens, these can create confusion about
where they are used. Make sure we encapsulate them in their own
class, so no confusion ensues.

JIRA: CONTROLLER-1919
Change-Id: I197b9118a5d9a09562db0a899bb6b8dc0dfae28b
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
4 years agoRename ValueTypes to LithiumValue
Robert Varga [Fri, 20 Sep 2019 17:59:04 +0000 (19:59 +0200)]
Rename ValueTypes to LithiumValue

These constants are only used in Lithium-based streams, make sure
we reflect that in the name of the class, so they do not end up
being confused.

JIRA: CONTROLLER-1919
Change-Id: I2e880b825d82b8a9b76008248d7663eab4bc1d71
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
4 years agoRename PathArgumentTypes to LithiumPathArgument
Robert Varga [Fri, 20 Sep 2019 17:55:39 +0000 (19:55 +0200)]
Rename PathArgumentTypes to LithiumPathArgument

These tokens are only used in Lithium-based streams, but the global
name is slightly confusing. Rename to LithiumPathArgument, which
makes the context more obvious.

JIRA: CONTROLLER-1919
Change-Id: I2b92be4c469de8dffba6e071449b5ae947b9ace8
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
4 years agoRename NodeTypes to LithiumNode
Robert Varga [Fri, 20 Sep 2019 17:54:04 +0000 (19:54 +0200)]
Rename NodeTypes to LithiumNode

This makes it clear these constants are only used in Lithium
encoding.

JIRA: CONTROLLER-1919
Change-Id: I1fb44f49d3409fdd007fe58dc6ce92b0eb6744b8
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
4 years agoMove Lithium tokens to their own class
Robert Varga [Fri, 20 Sep 2019 17:36:10 +0000 (19:36 +0200)]
Move Lithium tokens to their own class

TokenTypes assumes singularity, which can create confusion, as we
have multiple multiple distinct sets. This separates out
Lithium-specific tokens into their own class.

JIRA: CONTROLLER-1919
Change-Id: Id8c47be7c432b44980dbeac8ef41d430c64e5490
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
4 years agoMigrate from YangInstanceIdentifier.EMPTY
Robert Varga [Fri, 30 Aug 2019 09:10:53 +0000 (11:10 +0200)]
Migrate from YangInstanceIdentifier.EMPTY

This migrates to the replacement empty() method.

Change-Id: I32ca026a33835edb16f8e1e6142e9192c880076b
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
4 years agoSeparate out AbstractNormalizedNodeDataInput
Robert Varga [Tue, 17 Sep 2019 21:35:14 +0000 (23:35 +0200)]
Separate out AbstractNormalizedNodeDataInput

As we are going to introduce a streaming format for Magnesium, which
uses very different token set, it is convenient to have a common
base class which does not have conotations about what the tokens are.

We provide a baseline counterpart to AbstractNormalizedNodeDataOutput
and base AbstractLithiumDataInput on it. The asymmetry of
writeYangInstanceIdentifier() is fixed by moving it to
AbstractLithiumDataOutput.

Change-Id: I55d318349f2c89508f3834c8ca5b69e69b7171b1
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
4 years agoOptimize anyxml output
Robert Varga [Thu, 12 Sep 2019 15:33:59 +0000 (17:33 +0200)]
Optimize anyxml output

We do not need to instantiate a new factory every time we perform
encoding, keep the factory as a shared constant.

Change-Id: Ideff56076a1516784cd82f67438e5b740c4d3eeb
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
4 years agoMove Lithium-specific logic from AbstractNormalizedNodeDataOutput
Robert Varga [Wed, 11 Sep 2019 20:09:49 +0000 (22:09 +0200)]
Move Lithium-specific logic from AbstractNormalizedNodeDataOutput

The binding to TokenTypes and co. are really part of
AbstractLithiumDataOutput, as different serialization streams
versions can use completely different tokens and sizing.

Change-Id: I703c1da26ee2f99dee406e4de26db702beb05a06
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
4 years agoRemove ensureHeaderWritten() from writeNode()
Robert Varga [Wed, 11 Sep 2019 20:05:19 +0000 (22:05 +0200)]
Remove ensureHeaderWritten() from writeNode()

This updates documentation of AbstractNormalizedNodeDataOutput
to make it clear that the NormalizedNodeStreamWriter aspect of
it is an implementation detail and that the stream has been
header-initialized by the time any of those methods are called.

The clarification renders calling ensureHeaderWritten() from
writeNode() superfluous, as at that point it is guaranteed to
be a no-op.

Change-Id: I85a5c1304849fe5bc737fa51bd4b40ff2dd8c08c
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
4 years agoReorganize AbstractNormalizedNodeDataOutput
Robert Varga [Wed, 11 Sep 2019 15:44:47 +0000 (17:44 +0200)]
Reorganize AbstractNormalizedNodeDataOutput

This reorganizes AbstractNormalizedNodeDataOutput so that it
implements all NormalizedNodeDataOutput with final methods,
deferring implementation as need to abstract methods.

This way we have precisely one implementation of public methods,
making it easy to audit for correctness. Furthermore it eliminates
writeAugmentationIdentifier() override in NeonSR2 writer.

It also introduces writeQNameInternal(), which skips header checks,
as the call sites have already performed those checks.

Change-Id: Icb4a7e994c04e3d52bd561d99c7743dfdfd88738
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
4 years agoSplit out AbstractLithiumDataInput
Robert Varga [Sun, 8 Sep 2019 18:26:18 +0000 (20:26 +0200)]
Split out AbstractLithiumDataInput

This splits out AbstractLithiumDataInput and disconnects Lithium
and NeonSR2 reader implementations. This allows Neon SR2 to be loaded
without Lithium, thus reducing the number of actual possible
implementations at runtime.

Change-Id: I90863c342d7bbea4946fd27d25dfb822efb4ed6e
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
4 years agoCleanup PathArgumentTypes
Robert Varga [Wed, 11 Sep 2019 13:09:13 +0000 (15:09 +0200)]
Cleanup PathArgumentTypes

Do not use long qualifiers for individual types, preferring
importing them. Also drop public modifiers, as this class is
package-private. Finally import static checkArgument().

Change-Id: I267d0f5675911b2d9990e8f7c3fdd49265c10d8b
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
4 years agoAbstractNormalizedNodeDataOutput fails to write out header
Robert Varga [Wed, 11 Sep 2019 14:06:59 +0000 (16:06 +0200)]
AbstractNormalizedNodeDataOutput fails to write out header

In case AbstractNormalizedNodeDataOutput is used in a way, where
NormalizedNodeDataOutput.writePathArgument() is the first method
invoked, the stream header would not be output, leading to it
being unreadable.

Change-Id: I4ababb360129b2ef673d0546333599dd10fbdd9e
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
4 years agoTighten AbstractLithiumDataOutput.writeString()
Robert Varga [Sat, 7 Sep 2019 09:55:28 +0000 (11:55 +0200)]
Tighten AbstractLithiumDataOutput.writeString()

We can only ever pass nulls from Revision encoding, refactor to
make that clear (and enforced) in code. This more clearly defines
the context of TokenTypes.IS_NULL_VALUE and where it can be emitted.

Change-Id: I14045c9fc3eaf04b4bde858d322de45d3160de26
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
4 years agoRemove NormalizedNodeOutputStreamWriter
Robert Varga [Sat, 7 Sep 2019 09:22:39 +0000 (11:22 +0200)]
Remove NormalizedNodeOutputStreamWriter

This class is tied to NeonSR2 serialization format through subclassing,
where it really is a package-private detail. This leads to two concrete
classes being in existence for a particular format, which simply does
not make sense.

Eliminating this subclass allows us to make Neon SR2 final, thus arriving
and monomorphic or bimorphic invocation of all methods based on whether
we have seen Lithium (well, Oxygen) format at runtime.

Change-Id: I9e0463ec4879900e82cf757006dccfdbeb0d7297
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
4 years agoDisconnect {Lithium,NeonSR2} implementations
Robert Varga [Sat, 7 Sep 2019 07:54:32 +0000 (09:54 +0200)]
Disconnect {Lithium,NeonSR2} implementations

We will need to define two new serialization formats: one
sharing object value serialization (for NeonSR3) and one
disconnected from it (for Magnesium).

In order to maintain scalability with so many formats, we want
to avoid JIT considering implementations which were not referenced
at runtime. This should make CHA and method dispatch more
efficient.

Since we are isolating things, we also pull ValueTypes lookups
and keep it in the same class for easier understanding.

Change-Id: I3db4e9633db4a75016e17ac31bb38452bcb9f42a
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
4 years agoLower ValueTypes constant visibility
Robert Varga [Sat, 7 Sep 2019 07:01:43 +0000 (09:01 +0200)]
Lower ValueTypes constant visibility

This is a package-private class, hence 'public' is superfluous.

Change-Id: I4dd03b3ff1ae0cc4cc11f823cbd9538e6932d6b3
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
4 years agoCleanup ValueTypes lookup
Robert Varga [Wed, 28 Aug 2019 12:56:04 +0000 (14:56 +0200)]
Cleanup ValueTypes lookup

Change type of TYPES to ImmutableMap, so we are binding to a concrete
class when looking up. Also clean up initialization to follow fluent
builder pattern.

Finally inline requireNonNull() call into the invocation, so that its
return value is not wasted.

Change-Id: I4487bd43232131ca548441f4c8901a8c5dc60efa
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
4 years agoDeduplicate MapNode key leaf values
Robert Varga [Mon, 26 Aug 2019 20:44:30 +0000 (22:44 +0200)]
Deduplicate MapNode key leaf values

When we are encountering a leaf node inside a MapEntryNode, it can
be a leaf corresponding to a key -- in which case its value is
already present in NodeIdentifierWithPredicates and we do want to
de-duplicate those objects.

JIRA: CONTROLLER-1908
Change-Id: I2ed65c311f9921aa77c9f23bd1f7681d7f11355a
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
4 years agoMove common code to startNode()
Robert Varga [Tue, 27 Aug 2019 09:34:34 +0000 (11:34 +0200)]
Move common code to startNode()

We are duplicating null checks in all entrypoints which lead to
startNode(). We can centralize these in startNode(), leading to
denser code and fixing Sonar warnings.

Change-Id: I3f2a0c53216179e9d25624a3e3139340eff551fa
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
4 years agoRename SodiumNormalizedNode* classes
Robert Varga [Mon, 26 Aug 2019 22:08:05 +0000 (00:08 +0200)]
Rename SodiumNormalizedNode* classes

These are implementing Neon SR2 serialization format, hence they
should be named as such.

Change-Id: Iaa509e3490b420b8005a2724105bf99b53d95cf2
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
4 years agoDrop public modifier from NodeTypes
Robert Varga [Mon, 26 Aug 2019 21:17:51 +0000 (23:17 +0200)]
Drop public modifier from NodeTypes

The class itself is not visible outside of the package, there is no
point to declare the constants as public.

Change-Id: I4136a71c538452aba33a5abb3337e0f8fc7e8da8
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
4 years agoFix modernization issues
Robert Varga [Tue, 20 Aug 2019 19:06:59 +0000 (21:06 +0200)]
Fix modernization issues

This fixes issues pointed out by Modernizer, which mostly boil
down to using Objects.requireNonNull() and direct java.util
collections.

Change-Id: Id32530a6722cd101f96c23f6a745f91b2f09e2f9
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
4 years agoMigrate NodeIdentifierWithPredicates.getKeyValues()
Robert Varga [Tue, 20 Aug 2019 19:17:57 +0000 (21:17 +0200)]
Migrate NodeIdentifierWithPredicates.getKeyValues()

Change-Id: Iea47db72483111eea40374c23d7be0da33f67728
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
4 years agoConvert MessageTracker to use java.util.Optional
Robert Varga [Wed, 10 Jul 2019 13:30:22 +0000 (15:30 +0200)]
Convert MessageTracker to use java.util.Optional

This migrates from Guava, using Java 8 equivalent.

Change-Id: I71d01dae05e4f426406989d240c12745149d6964
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
4 years agoAdd support for reusable streaming
Robert Varga [Thu, 6 Jun 2019 10:26:37 +0000 (12:26 +0200)]
Add support for reusable streaming

With the actual implementations working on top of
NormalizedNodeStreamWriter, we gained the ability to flexibly
receive stream events.

This patch takes advantage of that flexibility by allowing
a ReusableImmutableNormalizedNodeStreamWriter to be the receiver
of the events -- thus allowing parts of the state involved in
building a NormalizedNode tree to be reused -- lowering GC
pressure.

A number of call sites, which can safely reuse such state are
converted to use the newly-introduced facility.

Change-Id: Iaf1b3ab2b2996e7004c036fc93a80a8ca8792314
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
4 years agoAdd streaming interface to NormalizedNodeDataInput
Robert Varga [Mon, 13 May 2019 05:44:05 +0000 (07:44 +0200)]
Add streaming interface to NormalizedNodeDataInput

NormalizedNodeDataInput allows reading NormalizedNodes, which is
wired directly to immutable node builders, providing little
flexibility.

This inflexibility requires us to re-stream the data set through
NormalizedNodePruner, effectively doubling memory requirements
during recovery.

Extend NormalizedNodeDataInput to have a NormalizedNodeStreamWriter
to be plugged in, so that the byte stream becomes a source of
NormalizedNodeStreamWriter events, which can be routed through
a custom-built pipeline.

readNormalizedNode() becomes a simple default wrapper, which
pipes the stream into an ImmutableNormalizedNodeStreamWriter.

JIRA: CONTROLLER-1889
Change-Id: Ic732ba9105dd7e27d5612853b931aba66bdd83a5
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
4 years agoFix multiple snapshots present after journal removal
Tomas Cere [Mon, 3 Jun 2019 13:02:08 +0000 (15:02 +0200)]
Fix multiple snapshots present after journal removal

After journal removal the sequence number starts counting from 0
once again. Therefore we can have multiple snapshots present and
snapshots with higher sequence number always take priority for loading
even when a newer snapshot is present.

Change this up in 2 ways:
1. disregard sequence number while deleting snapshots(delete all
snapshots with an older timestamp)
2. while loading snapshots prioritize timestamp rather than seqNr.

Also simplify LocalSnapshotStore.compare().

Change-Id: I205ea0ddf48d73b0a09297a1ce4e9fd514531993
Signed-off-by: Tomas Cere <tomas.cere@pantheon.tech>
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
4 years agoRename SODIUM versions to NEON_SR2
Robert Varga [Fri, 28 Jun 2019 11:37:50 +0000 (13:37 +0200)]
Rename SODIUM versions to NEON_SR2

We are shipping these improvements in Neon SR2, which means we
should reserve this version not as Sodium.

Change-Id: If5caa0dd7510c6e1ffe3c483c74c456798ca6bb3
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
5 years agoSwitch default output stream version
Robert Varga [Wed, 29 May 2019 16:17:13 +0000 (18:17 +0200)]
Switch default output stream version

All versioned callers have been converted to use appropriate
stream versions, this patch bumps the default unversioned stream
to Sodium version.

Since we're changing the serialization format for ExecuteRpc,
make sure we fully embrace writer/reader, so that we get better
instantiation.

JIRA: CONTROLLER-1888
Change-Id: I17deeda1a49394600a5b0f93bd46d3b2c812123c
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
5 years agoBump datastore version
Robert Varga [Wed, 29 May 2019 14:59:01 +0000 (16:59 +0200)]
Bump datastore version

This bumps the ask-based protocol datastore version, so that
SODIUM_VERSION is using Sodium NormalizedNode{Input,Output}.

JIRA: CONTROLLER-1888
Change-Id: Ib4ad1c27566179db958ad7776f81417ab99a78cf
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
5 years agoAdd QNameModule coding
Robert Varga [Thu, 6 Jun 2019 17:36:06 +0000 (19:36 +0200)]
Add QNameModule coding

Coding on QNames is effective when there are a lot of same QNames,
but there are cases where QNames themeselves are not reused --
for example YangInstanceIdentifiers and small read subtrees.

These typically end up using different QNames from a small set
of modules, hence coding modules actually helps them quite a bit.

This patch adds a namespace/revision cache, so that encoding such
QNames is also efficient.

JIRA: CONTROLLER-1898
Change-Id: I6cd0885ef605e4a1bf7b768ffe215e9eb3e2fbc5
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
5 years agoAdd buffering to LocalSnapshotStore
Tomas Cere [Tue, 4 Jun 2019 13:32:20 +0000 (15:32 +0200)]
Add buffering to LocalSnapshotStore

These improve snapshot save/load load times by around 15-20%
on my environment.

Change-Id: I67236f7e97f519993031d462c947588004857c33
Signed-off-by: Tomas Cere <tomas.cere@pantheon.tech>
5 years agoRemove use of thread-local input
Robert Varga [Mon, 3 Jun 2019 19:37:43 +0000 (21:37 +0200)]
Remove use of thread-local input

All callers are only called from top-level constructs, thus
not having a relationship with the context in which they are
deserialized.

JIRA: CONTROLLER-1888
Change-Id: I856f9109480fb83475a20ce4430d02a1dd055522
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
5 years agoTake advantage of AugmentationIdentifier.create()
Robert Varga [Tue, 4 Jun 2019 17:51:43 +0000 (19:51 +0200)]
Take advantage of AugmentationIdentifier.create()

When we are reading an augmentation identifier for the first
time we can optimize the number of identifiers by consulting
the global weak cache.

JIRA: CONTROLLER-1898
Change-Id: I5cd2d87e0a7c3f01357beb1b097d4a16a6eda3e0
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
5 years agoDo not use NodeIdentifierWithPredicates constructors
Robert Varga [Tue, 4 Jun 2019 17:05:55 +0000 (19:05 +0200)]
Do not use NodeIdentifierWithPredicates constructors

This class will transition into a value-based object for memory
efficiency reasons. Switch to using its static factory methods.

Change-Id: I7e21a6ccf1ad999d2d0427769b26dffeac166274
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
5 years agoOptimize readQNameSet()
Robert Varga [Tue, 4 Jun 2019 17:54:22 +0000 (19:54 +0200)]
Optimize readQNameSet()

We are providing a bad hint to HashSet, as we are not taking
into consideration its load factor. Use utility methods from Guava
to get a properly-sized set.

JIRA: CONTROLLER-1898
Change-Id: I568be3040b924a8ed77aa0224ab45673104c4664
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
5 years agoRemove use of thread-local output
Robert Varga [Mon, 3 Jun 2019 19:12:44 +0000 (21:12 +0200)]
Remove use of thread-local output

All callers can be safely migrated to using a non-shared writer,
as they all are expected to be apex implementations.

JIRA: CONTROLLER-1888
Change-Id: I87cfa1d3ec415b79c40c29a91ccbd8da2869b27a
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
5 years agoMove byte-based serialization method
Robert Varga [Mon, 3 Jun 2019 18:52:36 +0000 (20:52 +0200)]
Move byte-based serialization method

This is only used in testing, move the method out to testing class.

JIRA: CONTROLLER-1888
Change-Id: Ib18be55467561a2471a74285b062b40d4e9e08c8
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
5 years agoOptimize NodeIdentifier reading
Robert Varga [Wed, 29 May 2019 10:10:52 +0000 (12:10 +0200)]
Optimize NodeIdentifier reading

NodeIdentifiers are just an alias for QName, which is heavily
reused. This patch adds a secondary cache for interpreting QNames
as NodeIdentifiers, with instance reuse.

This allows us to reduce the number of NodeIdentifier instances,
while not relying on NodeIdentifier.create() for the common lookup
case.

JIRA: CONTROLLER-1898
Change-Id: Ifa0c5d572f7d39da49707529c7ddd9c9f36f2dab
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
5 years agoAdd support for coded QNames/AugmentationIdentifiers
Robert Varga [Wed, 29 May 2019 09:27:21 +0000 (11:27 +0200)]
Add support for coded QNames/AugmentationIdentifiers

Profiling is showing we are spending about 46% in readQName(),
which further breaks down to 30% in readCodedString() and 61%
in QNameFactory.create().

Out of 1.7M invocations of readQName(), we end up loading only
508 QNames -- which is understandable, as the number of QNames is
bound by the SchemaContext contents. This also applies to
AugmentationIdentifiers.

This patch defines a new streaming format version, which uses
the same linear coding approach we take for Strings, taking
hash-based lookups out of the hot path -- bringing reconstruction
time down from 36 to 19-24 seconds.

It has also the effect of reducing the snapshot size, in our testing
bringing a 388.8MiB snapshot down to 210.6MiB.

JIRA: CONTROLLER-1898
Change-Id: Ibbc96c286d52b3261b04dd7de02e13bc6b44e803
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
5 years agoSeparate lazy-versioned NormalizedNodeDataInput
Robert Varga [Tue, 28 May 2019 13:28:55 +0000 (15:28 +0200)]
Separate lazy-versioned NormalizedNodeDataInput

NormalizedNodeInputStreamReader is really only one implementation
of the streaming format, which happens to be bound to LITHIUM_VERSION.

This effectively means NormalizedNodeInputOutput can give out either
a version-bound reader or an unbound reader -- which we facilitate by
creating VersionedNormalizedNodeDataInput which is a simple forwarder
with lazily-initialized delegate.

Since this increases the number of (NormalizedNode)DataInput
implementations, we share as much code as possible through the use
of forwarding implementations.

JIRA: CONTROLLER-1898
Change-Id: I28713346730ed5bf7f912bf8afa5d8722b202035
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
5 years agoDo not format QNames to string on input
Robert Varga [Tue, 28 May 2019 11:14:34 +0000 (13:14 +0200)]
Do not format QNames to string on input

Profiling has revelead the creation of String for QNameFactory
lookup is taking around 19% of overall cost of
NormalizedNodeInputStreamReader.readQName().

Rather than using concatenation, use a dedicated Key object, which
holds the separated-out localname/namespace/revision strings,
thus allocating a small object instead of a full-blown String.

This improves snapshot deserialization perfomance on a 350MiB
snapshot by about 16%, also resulting in lower memory pressure.

JIRA: CONTROLLER-1897
Change-Id: If3e9e4b332b0a5acbe33aa10fca189bbc7da8c81
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
5 years agoUpdate QNameFactory caching
Robert Varga [Tue, 28 May 2019 10:42:02 +0000 (12:42 +0200)]
Update QNameFactory caching

This eliminates the use of soft references in favor of weak ones,
so that we do not rely on GC heuristics for retention.

We also make the maximum cache size runtime-configurable via
org.opendaylight.controller.cluster.datastore.node.utils.qname-cache.max-size
property.

Finally we use QName.intern() to defer to the global QName cache,
resulting in better QName instance sharing.

JIRA: CONTROLLER-1897
Change-Id: Ice3596d23b96c4ecfc5775cb21968233b042a984
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
5 years agoUse Files.delete() in LocalSnapshotStore
Tomas Cere [Thu, 23 May 2019 08:04:16 +0000 (10:04 +0200)]
Use Files.delete() in LocalSnapshotStore

If delete fails, it needs to be logged so change this up.

Change-Id: If4051cb3e5b83dee51f919fc1713cc17f032597e
Signed-off-by: Tomas Cere <tomas.cere@pantheon.tech>
5 years agoCentralize read{Augmentation,Node}Identifier() methods
Robert Varga [Mon, 13 May 2019 05:53:27 +0000 (07:53 +0200)]
Centralize read{Augmentation,Node}Identifier() methods

We are using the same construct in multiple places, make sure we
centralize it and mark a FIXME for some efficiency increase.

Change-Id: Ie65089a1a7bb6a2752887498d354a61cb32f0e40
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
5 years agoBump yangtools to 3.0.0
Robert Varga [Fri, 22 Mar 2019 18:32:29 +0000 (19:32 +0100)]
Bump yangtools to 3.0.0

This is bumps yangtools to 3.0.0, adjusting for changed APIs. The
changes specifically include:

- use ListenerRegistry.getRegistrations() instead of it implementing
  Iterable
- adjust for NormalizedNodeStreamWriter interface change
- remove use of *AttrBuilder, as NormalizedNodes no longer hold
  attributes
- DataTreeCandidateNodes.empty() instead of home-grown implementation
- adjust for DataTreeCandidateNode.getModifiedChild() returning Optional
- use QueuedNotificationManager.BatchedInvoker

Change-Id: Ia30d73ccf6380e3759414b3026b822df0950a481
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
5 years agoBump odlparent to 5.0.0
Robert Varga [Fri, 22 Mar 2019 18:31:50 +0000 (19:31 +0100)]
Bump odlparent to 5.0.0

This bumps odlparent references to 5.0.0, removing use of the JSR305
remnants. Also a useless javadoc plugin override is removed.

Change-Id: Iae5355e49115afdd73b60bd26ac85f7f542bbff8
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
5 years agoMigrate to AbstractActor
Robert Varga [Tue, 19 Feb 2019 14:58:28 +0000 (15:58 +0100)]
Migrate to AbstractActor

UntypedActor has been deprecated, this patch migrates to using
AbstractActor so we eliminate a slew of deprecatation warnings.

Change-Id: I4e3274ce92d5f68df1937f91f823eed905da4d6c
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
Signed-off-by: Ajay Lele <ajayslele@gmail.com>
5 years agoFix logging messages
Robert Varga [Thu, 28 Mar 2019 13:32:44 +0000 (14:32 +0100)]
Fix logging messages

Upgraded spotbugs is finding more violations, fix them up.

Change-Id: I8956c5b7a6eef38286f4c2b6fb07ca6a775e6965
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
5 years agoAdd ReusableNormalizedNodePruner
Robert Varga [Thu, 28 Mar 2019 11:46:34 +0000 (12:46 +0100)]
Add ReusableNormalizedNodePruner

This version of NormalizedNodePruner is reusable across invocations,
and improving CPU and memory efficiency in bulk operations due to
not needing to allocate stack nor lookup DataSchemaContextTree.

JIRA: CONTROLLER-1887
Change-Id: I1798f5f6255cd23702bf3792c1f4f5149f92d208
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
5 years agoMove checkNotSealed() to addBuilder()
Robert Varga [Thu, 28 Mar 2019 10:22:55 +0000 (11:22 +0100)]
Move checkNotSealed() to addBuilder()

addBuilder() is called after previous check for seal from all callers,
who do not have any side-effects aside allocating arguments to
addBuilder().

Move the call to checkNotSealed() to addBuilder(), making the code
more straightforward and possibly preventing bugs from creeping in.

JIRA: CONTROLLER-1887
Change-Id: I127385378957deb7f38f1203870a0e52cd630644
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
5 years agoRemove NormalizedNodePruner.findSchemaNodeForNodePath()
Robert Varga [Thu, 28 Mar 2019 10:16:27 +0000 (11:16 +0100)]
Remove NormalizedNodePruner.findSchemaNodeForNodePath()

DataSchemaContextTree.findChild() provides equivalent functionality,
so use that instead of brewing our own.

JIRA: CONTROLLER-1887
Change-Id: Ia55ac99ce8fa37daf06ce0e7e1615f1bd0a07123
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
5 years agoDo not use Optional in NormalizedNodeWrapper
Robert Varga [Thu, 28 Mar 2019 09:58:49 +0000 (10:58 +0100)]
Do not use Optional in NormalizedNodeWrapper

Use nullable schema instead, as the caller is package-private and
ends up unpacking the return anyway. This simplifies
NormalizedNodePruner a bit.

JIRA: CONTROLLER-1887
Change-Id: I395dd8266bd7198f66890c4ae3633ecda9281726
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
5 years agoHide NormalizedNodeBuilderWrapper
Robert Varga [Thu, 28 Mar 2019 07:48:02 +0000 (08:48 +0100)]
Hide NormalizedNodeBuilderWrapper

This class is not instantiable outside of the package is it does
not leak from NormalizedNodePruner -- therefore it cannot be used
by anyone else. Make sure it's package-private and clean it up
a bit.

JIRA: CONTROLLER-1887
Change-Id: I17911508273d68c2795d38e2156c9407522f55fe
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
5 years agoRemove NormalizedNodePruner.SimpleStack
Robert Varga [Wed, 27 Mar 2019 22:51:57 +0000 (23:51 +0100)]
Remove NormalizedNodePruner.SimpleStack

This custom implementation is highly inefficient, because:
1) peek/pop operations perform get(int) and remove(int) operations
   on ArrayList, which are highly inefficient O(N)
2) it allocates an object for each entry

Replace this class with a stock Deque, which takes care of the first
problem, as push/pop/peek are amortized O(1).

For implementation use an ArrayDeque, which takes care of the second
problem, as stack entries are reused.

Change-Id: Ie59e2fb47f841e4e5fc08c3ab7e164ad0cb368ad
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
5 years agoClean up NormalizedNodePruner
Robert Varga [Wed, 27 Mar 2019 22:45:15 +0000 (23:45 +0100)]
Clean up NormalizedNodePruner

- shorten YangInstanceIdentifier.PathArgument references
- do not declare runtime exceptions as thrown
- use a space after comma

Change-Id: Id0f09d2cd72bc619331c2d16e8f184db784c9976
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
5 years agoUse a simple list for string code table
Robert Varga [Fri, 15 Mar 2019 11:33:05 +0000 (12:33 +0100)]
Use a simple list for string code table

Since the codes are assigned in a linear fashion, we can use
a simple ArrayList to track assignes codes, preventing the need
for boxing integer during population and lookups. Lookups also
end up requiring an array offset lookup rather than needing
to go through multiple indirections.

While this can in theory lead to a large array being allocated,
the set of strings we keep in the table is limited by the
SchemaContext and thus will be typically capped ad couple of
thousand.

The cost of growing the lookup should not be significantly
higher, even if ArrayList grows slower:
- 10, 16, 25, 38,  58,  88
versus HashMap (with .75 load factor)
- 12, 24, 48, 96, 192, 384

each resize operation is significantly faster.

Change-Id: I00c7a2e0985dbf901b6857a16424bf157e5af39d
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
5 years agoImprove NormalizedNodeInputStreamReader defensiveness
Robert Varga [Fri, 15 Mar 2019 11:20:24 +0000 (12:20 +0100)]
Improve NormalizedNodeInputStreamReader defensiveness

If face of corrupted streams, for example due to CONTROLLER-1752,
we can end up interpreting unknown bytes as null strings, potentially
corrupting data.

This patch uses explicit type dispatch and detects wrong string
value types, as well as rejecting unknown string value codes.

Change-Id: Ic2e7887bc1d32a1dc7a364d1bff195752edd762d
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
5 years agoReduce JSR305 proliferation
Robert Varga [Thu, 7 Feb 2019 16:53:09 +0000 (17:53 +0100)]
Reduce JSR305 proliferation

retention=runtime annotations are mixing really badly with Java EE
injection and Java 11.

Make sure we do not use javax.annotation package in APIs and reduce
overall proliferation inside implementations.

Change-Id: I569815f0336efdc0de662c3b80f0fa6e5dd47d8a
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
5 years agoSwitch to spotbugs
Robert Varga [Thu, 27 Dec 2018 03:46:10 +0000 (04:46 +0100)]
Switch to spotbugs

Rather than using findbugs, use spotbugs, which works with Java 9.

Change-Id: I8807b2dc34fdb4ddfd476a2a0ed9cf0db2e044cd
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
5 years agoImprove timeout check error message
Robert Varga [Wed, 5 Dec 2018 10:26:34 +0000 (11:26 +0100)]
Improve timeout check error message

Report the value being set in checkArgument.

Change-Id: I76e88504f794300634f61b293876e1677c549792
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
5 years agoImprove NormalizedNodeInputStreamReader
Robert Varga [Sun, 25 Nov 2018 17:29:17 +0000 (18:29 +0100)]
Improve NormalizedNodeInputStreamReader

We really want to retain source iteration order of predicates
being streamed into the system, as they usually match the order
locally.

Refactor NormalizedNodeInputStreamReader to read complete
NodeIdentifierWithPredicate objects, thus allowing us to use
ImmutableOffsetMapTemplate to skip some data checks and copying
around.

MDSAL: YANGTOOLS-917
Change-Id: I162919c7e56109fc98933a4eeae8669b030dc992
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
5 years agoUse pre-sized ImmutableLists for yang-data-api
Robert Varga [Sun, 25 Nov 2018 17:23:50 +0000 (18:23 +0100)]
Use pre-sized ImmutableLists for yang-data-api

ImmutableList.builder() did not pre-size its arrays correctly,
leading to poor performance. That is no longer the case and we can
correctly pre-allocate it -- giving us the ArrayList equivalent in
immutable form, hence skipping copying in
{SchemaPath,YangInstanceIdentifier}.create()

Change-Id: I4a070dca26138f28de69e4a0e1f9b0298ee2312b
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
5 years agoIntegrate MRI projects for Neon
Robert Varga [Mon, 6 Aug 2018 13:27:49 +0000 (15:27 +0200)]
Integrate MRI projects for Neon

This patch bumps:
- odlparent to 4.0.2
- yangtools to 2.1.2
- mdsal to 3.0.1

It also deals with:
- DOMRpcError.getErrors() changing
- java.util.Optional being used in MD-SAL
- xmlunit upgrade via xmlunit-legacy
- any(Class) not matching nulls
- lists disappearing and hence requiring at least one item
- remove explicit <null/> in blueprints, as that breaks blueprint-core
- adjust sal-binding-it to include byte-buddy, which is a mockito dependency
- adjust dependencies to account for ietf-{inet,yang}-types movement
- moving to tech.pantheon.triemap
- mdsal.common.api removals

JIRA: CONTROLLER-1860
Change-Id: I31b2d011015846537a99f963ded1d38e7b29d71e
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
5 years agoBump to Dropwizard Metrics 4.0.3
Stephen Kitt [Tue, 25 Sep 2018 10:24:24 +0000 (12:24 +0200)]
Bump to Dropwizard Metrics 4.0.3

This also cleans up some duplicate dependencies.

Release notes:
* 4.0.0: https://metrics.dropwizard.io/4.0.0/about/release-notes.html
* 4.0.1: https://github.com/dropwizard/metrics/releases/tag/v4.0.1
* 4.0.2: https://github.com/dropwizard/metrics/releases/tag/v4.0.1
* 4.0.3: none available, see
  https://github.com/dropwizard/metrics/compare/v4.0.2...v4.0.3

Change-Id: I29050a587aebafcf0d169425242b6281dbb43519
Signed-off-by: Stephen Kitt <skitt@redhat.com>
5 years agoFix findbugs warnings
Robert Varga [Mon, 20 Aug 2018 23:07:54 +0000 (01:07 +0200)]
Fix findbugs warnings

Upgraded findbugs finds these, fix them up.

Change-Id: Id5a008cddc6616c3a93f0528efca00b86843fc3c
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
5 years agoMigrate to UntypedAbstractActor
Robert Varga [Fri, 6 Apr 2018 12:15:35 +0000 (14:15 +0200)]
Migrate to UntypedAbstractActor

As per the 2.4-to-2.5 migration guide using UntypedAbstractActor
UntypedActor is our cheapest migration option. This requires
updating MeteringBehavior to integrate with Receive.

Change-Id: I692f723dffc966bb7e117124b7a0cd714572ab4f
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
5 years agosimplify a statement in NormalizedNodeInputStreamReader
Michael Vorburger [Wed, 25 Jul 2018 21:47:46 +0000 (23:47 +0200)]
simplify a statement in NormalizedNodeInputStreamReader

and fix a JavaDoc warning in NormalizedNodeOutputStreamWriter

Change-Id: I471dc3d4c8d1327fa8adaca89b8ca1d46036929d
Signed-off-by: Michael Vorburger <vorburger@redhat.com>
5 years agoSimplify code using Java 8 features
Stephen Kitt [Mon, 23 Jul 2018 15:31:33 +0000 (17:31 +0200)]
Simplify code using Java 8 features

* List::sort
* lambda expressions
* Comparator::comparing...
* Collection::removeIf
* method references
* Map::computeIfAbsent
* Map::merge

Change-Id: I1793591c071c7ce5465939afe8b4846b769b5953
Signed-off-by: Stephen Kitt <skitt@redhat.com>
5 years agoRemove unused exceptions
Stephen Kitt [Mon, 23 Jul 2018 14:45:38 +0000 (16:45 +0200)]
Remove unused exceptions

This drops exception declarations which are never used.

Change-Id: Icc8938b9c3b437a0d5961ec1b481fd06c52d47f2
Signed-off-by: Stephen Kitt <skitt@redhat.com>
6 years agoRemove CSS modules
Tom Pantelis [Mon, 4 Jun 2018 21:46:56 +0000 (17:46 -0400)]
Remove CSS modules

The CSS features are still installed until we can work
out the ModuleInfoBackedContext/ClassLoaderStrategy situation
that is currently provided by the ConfigManagerActivator.

Change-Id: Id3b2cc287d17532482a2dd893c41e2dcd8d29ff0
Signed-off-by: Tom Pantelis <tompantelis@gmail.com>
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
6 years agoHandle empty type in NormalizedNode streaming
Tom Pantelis [Sat, 20 Jan 2018 00:19:03 +0000 (19:19 -0500)]
Handle empty type in NormalizedNode streaming

The yang "empty" type is now represented as
org.opendaylight.yangtools.yang.common.Empty so handle it.

NormalizedNode no longer allows a null value but we still need
to handle NULL_TYPE on input for backwards compatibility. NULL_TYPE
is translated to Empty.

Change-Id: I99b87138d7358d37170cf603d993cd1a4f6a2087
Signed-off-by: Tom Pantelis <tompantelis@gmail.com>
6 years agoAdjust to yangtools-2.0.0 changes
Robert Varga [Wed, 11 Oct 2017 19:31:07 +0000 (21:31 +0200)]
Adjust to yangtools-2.0.0 changes

Change-Id: Ib86747e5ed19c0c00bb46b8d7e4936f4d90c4364
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
Signed-off-by: Stephen Kitt <skitt@redhat.com>
6 years agoFix checkstyle reported by odlparent-3.0.0
Robert Varga [Thu, 16 Nov 2017 02:34:13 +0000 (03:34 +0100)]
Fix checkstyle reported by odlparent-3.0.0

Change-Id: I08c548fbbbef8527ad7b037b0def33d3c1c09bf6
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
6 years agoFix some sonar/checkstyle issues
David Suarez [Sat, 14 Oct 2017 13:49:21 +0000 (15:49 +0200)]
Fix some sonar/checkstyle issues

- Remove unnecessary boxing
- Utility classes should be final and implement a private constructor
- Remove unnecessary types
- Remove two duplicated entries in pom.xml

Change-Id: I2f4539babf7d4ea6d4550d81b71deb4399dc1dc3
Signed-off-by: David Suarez <david.suarez.fuentes@gmail.com>
6 years agoString performance and maintenability
Stephen Kitt [Thu, 18 May 2017 13:28:46 +0000 (15:28 +0200)]
String performance and maintenability

Use StringBuilder for strings built in loops. Use plain concatenation
for string construction not involving loops.

Change-Id: I8299eb54a347d132f0d19dfb39c8fb52366049f2
Signed-off-by: Stephen Kitt <skitt@redhat.com>
6 years agoBug 9008: Fix the error of the persisted journal data format
HeYunBo [Fri, 18 Aug 2017 12:31:39 +0000 (20:31 +0800)]
Bug 9008: Fix the error of the persisted journal data format

We have to clear the lastLeafSetQName while processing the end event for node
in NormalizedNodeInputStreamReader and AbstractNormalizedNodeDataOutput.

Otherwise while processing the leaf-list node, the leaf-list entry node
may use the other LeafSetQName as it's node identifier incorrectly.
The DataTree reconstructed from the persisted journal after the controller
restart will be not equal to the DataTree before restart under certain
circumstances.

Change-Id: I4ee823f59fe477d08f982ae73e3850433dfea8ee
Signed-off-by: HeYunBo <he.yunbo@zte.com.cn>
6 years agoBUG-9028: make NonPersistentDataProvider schedule invocation
Robert Varga [Tue, 22 Aug 2017 17:59:21 +0000 (19:59 +0200)]
BUG-9028: make NonPersistentDataProvider schedule invocation

We need to make NonPersistentDataProvider behave in a fashion
similar to what PersistentDataProvider does for asynchronous
persistence calls, which is schedule execution of the provided
procedure rather than direct execution (which is fair for synchronous
execution).

In order to make that work we introduce ExecuteInSelfActor, which
has an executeInSelf() method, which uses internal mechanics to
schedule the call at a later point.

Change-Id: I116708d98154c8244ea80b4a1a1aa615abc3075d
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
(cherry picked from commit b66d6180f06097e3501a88aac9fb684336addd58)

6 years agoSlice front-end request messages
Tom Pantelis [Wed, 19 Jul 2017 20:47:28 +0000 (16:47 -0400)]
Slice front-end request messages

Added infrastructure to use the MessageSlicer to slice SliceableMessages in
the TransmitQueue.Transmitting class on the front-end. A MessageAssembler is
used on the Shard side to re-assemble. Currently only the
front-end ModifyTransactionRequest is a SliceableMessage as it contains a
NormalizedNode which can be arbitrarily large - the others are small and
don't require slicing.

Change-Id: I7b09e4864e19d3fdb215c2b9dbcb64c14b6a143c
Signed-off-by: Tom Pantelis <tompantelis@gmail.com>
6 years agoSimplify QuarantinedMonitorActor
Robert Varga [Mon, 17 Jul 2017 12:57:08 +0000 (14:57 +0200)]
Simplify QuarantinedMonitorActor

As per the comments, upstream has provided a dedicated event, hence
use that instead of digging inside akka internals.

Change-Id: I4731dfbbdd228d562ddd32ec5fd3d0e9af0855d0
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
6 years agoCleanup warnings
Robert Varga [Tue, 27 Jun 2017 21:43:40 +0000 (23:43 +0200)]
Cleanup warnings

- pom.xml groupId duplicate
- Futures.addCallback()
- Throwables.propagate*()
- pontentially-static methods
- remove 'throws Exception' where it is not really needed

Change-Id: Ib47e6255e0f510ab7dd0dcd08f71f2dd124df7b7
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
6 years agoFix incorrect spelling of fileBackedStreamFactory
Tom Pantelis [Fri, 7 Jul 2017 08:53:14 +0000 (04:53 -0400)]
Fix incorrect spelling of fileBackedStreamFactory

filedBackedStreamFactory should be fileBackedStreamFactory.

Change-Id: Ib0b65d68d37c5b0ded4f1739d4ddc578973fe6ec
Signed-off-by: Tom Pantelis <tompantelis@gmail.com>
6 years agoBug 7449: Add slicer Id to MessageSliceIdentifier
Tom Pantelis [Mon, 3 Jul 2017 17:00:07 +0000 (13:00 -0400)]
Bug 7449: Add slicer Id to MessageSliceIdentifier

Both Shard and RaftActor (via AbstractLeader) (will) have separate
MessageSlicer instances and we need to determine to which instance
MessageSliceReply messages should be forwarded otherwise the first
MessageSlicer will drop messages destined for the second MessageSlicer.
Therefore add a slicerId field to MessageSliceIdentifier which is
checked by MessageSlicer#handleMessage.

Change-Id: Ib39ede29789d5bfaf1fdaea66a8d2994fe6ebcd6
Signed-off-by: Tom Pantelis <tompantelis@gmail.com>
7 years agoBug 2890: Chunk AppendEntries when single payload size exceeds threshold
Tom Pantelis [Thu, 18 May 2017 13:23:04 +0000 (09:23 -0400)]
Bug 2890: Chunk AppendEntries when single payload size exceeds threshold

Utilizes the MessageSlicer in AbstractLeader to slice/chunk AppendEntries
messages whose single log entry payloas exceeds the max size threshold.
The MessageAssembler is used in the Follower to re-assemble.

For efficiency, with multiple followers, the AbstractLeader reuses the
FileBackedOutputStream containing the serialized AppendEntries data.
However, since the MessageSlicer takes ownership of the FileBackedOutputStream
and cleans it up when slicing is complete, I added a
SharedFileBackedOutputStream class that maintains a usage count and
performs cleanup when the usage count reaches 0. The AbstractLeader maintains
a Map of SharedFileBackedOutputStream instances keyed by log index.

The FollowerLogInformation keeps track of whether or not slicing is in
progress for the follower. Same as with install snapshot, we only want to send
empty AppendEntries as heartbeats.

Change-Id: Id163944b9989f6cb39a6aaaa98d1f3c4b0026bbe
Signed-off-by: Tom Pantelis <tompantelis@gmail.com>
7 years agoBug 7449: Move Dispatchers to sal-clustering-commons
Tom Pantelis [Fri, 23 Jun 2017 11:49:48 +0000 (07:49 -0400)]
Bug 7449: Move Dispatchers to sal-clustering-commons

Moved Dispatchers to a common package so it can be used in
cds-access-client.

Change-Id: I4cea4c586dded9e413c1feee698b04d981b19ea2
Signed-off-by: Tom Pantelis <tompantelis@gmail.com>
7 years agoBug 7449: Add message slicing/re-assembly classes
Tom Pantelis [Thu, 20 Apr 2017 13:10:05 +0000 (09:10 -0400)]
Bug 7449: Add message slicing/re-assembly classes

Added re-usable classes for slicing messages into smaller chunks and
re-assembling them. The process is similar to the current raft
install snapshot chunking.

The 2 main classes are MessageSlicer and MessageAssembler. The basic workflow
is:

 - MessageSlicer#slice method is called which serializes the message,
   creates and caches a SlicedMessageState instance and determines the number
   of slices based on the serialized size and the maximum message slice size,
   then sends the first MessageSlice message.
 - The MessageAssembler on the other end receives the MessageSlice, creates an
   AssembledMessageState instance if necessary and appends the byte[] chunk to
   the assembled stream. A MessageSliceReply is returned.
 - The MessageSlicer receives the MessageSliceReply and sends the next
   MessageSlice chunk, if necessary.
 - Once the last MessageSlice chunk is received by the MessageAssembler, it
   re-assembles the original message by de-serializing the assembled stream
   and notifies the user-supplied callback (of type Consumer<Object>) to handle
   the message.

Both MessageSlicer and MessageAssembler use a guava Cache and can be configured
to evict state that has been inactive for a period of time, ie if a message hasn't
been received by the other end.

The MessageSliceReply can propagate a MessageSliceException. If the
MessageSliceException indicates it's re-triable, the MessageSlicer will restart
slicing from the beginning. Otherwise slicing is aborted and the user-supplied
failure callback is notified.

Change-Id: Iceea212b12f49c3944bade50afded92244e4b31a
Signed-off-by: Tom Pantelis <tompantelis@gmail.com>
7 years agoLower UnboundedDequeBasedControlAwareMailbox logging
Robert Varga [Mon, 19 Jun 2017 11:53:26 +0000 (13:53 +0200)]
Lower UnboundedDequeBasedControlAwareMailbox logging

Using debug logging seems excessive, leading to a lot of messages
at debug level. I think we can downgrade to trace instead.

Change-Id: I2a7f87760a1eefe9794eac3b4025b6a3891c30a3
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
(cherry picked from commit 27193873ccddbdc8126a24cdb9b0536c5e98ae5f)

7 years agoRemove deprecated NormalizedNodeInputStreamReader ctor
Tom Pantelis [Tue, 30 May 2017 13:16:28 +0000 (09:16 -0400)]
Remove deprecated NormalizedNodeInputStreamReader ctor

The intent is for NormalizedNodeInputStreamReader to be package-scoped
and to create instances via NormalizedNodeInputOutput#newDataInput.
Thus the deprecated public constructor was removed and the remaining
users were converted to use NormalizedNodeInputOutput#newDataInput.
However newDataInput has the side-effect of validating the input stream
first which failed for a couple users who need to lazily do the
validation so I added a newDataInputWithoutValidation method.

Change-Id: Ieb97ab77d05d7a4401dd0526cd4df3a5eafc9eda
Signed-off-by: Tom Pantelis <tompantelis@gmail.com>
7 years agoBug 5740: Add Deque-based control-aware mailbox
Tom Pantelis [Thu, 25 May 2017 13:39:40 +0000 (09:39 -0400)]
Bug 5740: Add Deque-based control-aware mailbox

Since akka persistence uses stashing, it requires a mailbox to be
Deque-based to provide the enqueueFirst method. However, the
control-aware mailboxes provided by akka are not Deque-based so we
need one that is.

Change-Id: I74f214c725eff16aba093aad3f2f6eed80948ee4
Signed-off-by: Tom Pantelis <tompantelis@gmail.com>
7 years agoLower debugging in sal-clustering-commons
Robert Varga [Tue, 16 May 2017 11:54:24 +0000 (13:54 +0200)]
Lower debugging in sal-clustering-commons

Since this component is under controller.cluster.datastore,
it floods logs with serialization details when we really just
want to understand what the data store is doing. Lower the logs
to TRACE.

Change-Id: Ib9a4735bc439a726452fb98fb5f79d2b7dea2047
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
7 years agosal-clustering-commons: use lambdas
Stephen Kitt [Tue, 16 May 2017 15:51:11 +0000 (17:51 +0200)]
sal-clustering-commons: use lambdas

This series of patches uses lambdas instead of anonymous classes for
functional interfaces when possible. Lambdas are replaced with method
references when appropriate.

Change-Id: I2a4a800267cd00e9564dfa8b3af069fc14542f61
Signed-off-by: Stephen Kitt <skitt@redhat.com>