Skip to content

Refactoring of amber engine - #2208

Merged
shengquan-ni merged 88 commits into
masterfrom
shengquan-refactor-1
Nov 16, 2023
Merged

Refactoring of amber engine#2208
shengquan-ni merged 88 commits into
masterfrom
shengquan-refactor-1

Conversation

@shengquan-ni

@shengquan-ni shengquan-ni commented Nov 6, 2023

Copy link
Copy Markdown
Contributor

Purpose of Refactoring

Supporting Checkpoints:

  1. Channel Clarity and Message Handling: Previously, the worker's handling of messages in channels was ambiguous, using various message classes to differentiate channels. This led to code duplication and complexity for implementing checkpoints.
  2. State Management: The components within a worker are well-organized. This disorganization would complicate future implementations of state serialization and deserialization.

Architectural Improvements:

  1. Worker Architecture Cleanup: The existing worker architecture has evolved in an ad-hoc manner, leading to a lack of clarity. An example is the Network Communicate Actor, which needs a redesign for better maintainability.

Current Worker Architecture

See the current architecture diagram here: Texera Overall Infrastructure

Key Refactorings in This PR

Supporting Checkpoints:

  1. Message Class Unification: Introduced a unified message type WorkflowFIFOMessage with a ChannelID to clearly identify communication channels, reducing code duplication.
  2. Actor Component Extraction: Separated actor-related components (like Actor context, timers, flow control and congestion control) from DP, integrating them into the main actor for better alignment with the Akka actor system and avoiding serialization.
  3. Core State Introduction: Established a core state within the actor(i.e. DataProcessor, AmberProcessor) for serialization during checkpoints, ensuring non-core states are excluded from serialization processes.

Architectural Improvements:

  1. Network Communication Actor Removal: Transferred all messaging responsibilities to the main actor, including sending messages and receiving acks. Flow and congestion controls have been refactored on a per-channel basis.
  2. Renaming for Clarity: Changed NetworkInputPort and NetworkOutputPort to NetworkInputGateway and NetworkOutputGateway, reflecting their roles in managing multiple channels.
  3. Enhanced Testing: Added additional test cases for Java/Python workers.

Temporary Changes:

Post-Refactoring Worker Architecture

View the updated architecture diagram here: Refactored Worker Architecture

Flow control

After this PR, the credit of flow control is not sent back with the acks. We poll from the downstream operator whenever the credit is not enough. This will be fixed later with a new flow control design.

Base automatically changed from shengquan-refactor-amber-3-dup to master November 10, 2023 04:09
@shengquan-ni shengquan-ni removed their assignment Nov 15, 2023
This is a follow-up PR after #2208, which focused on refactoring of the
controller and workflow execution states.

## Problem of Serializing Controller State
The controller holds the workflow, scheduler, and execution state,
however, many of them are not serializable because they have deep
dependencies with third-party libs such as jgrapht, akka.

## Changes in This PR
Separated the execution state from the workflow in another class called
`ExecutionState`, which is completely serializable. It includes the
execution runtime state of all the workers, edges, and regions.

### Controller Refactoring
Following #2208, the controller also creates its core state
(ControllerProcessor) and all serializable components are put into this
core state.
@shengquan-ni shengquan-ni changed the title [1/2] Refactoring of amber worker and DP thread Refactoring of amber engine Nov 15, 2023
@Yicong-Huang Yicong-Huang added the refactor Refactor the code label Nov 15, 2023
@shengquan-ni
shengquan-ni merged commit 2f89af4 into master Nov 16, 2023
@shengquan-ni
shengquan-ni deleted the shengquan-refactor-1 branch November 16, 2023 00:42
Xiao-zhen-Liu pushed a commit that referenced this pull request Jan 16, 2024
## Purpose of Refactoring
### Supporting Checkpoints:
1. **Channel Clarity and Message Handling**: Previously, the worker's
handling of messages in channels was ambiguous, using various message
classes to differentiate channels. This led to code duplication and
complexity for implementing checkpoints.
2. **State Management**: The components within a worker are
well-organized. This disorganization would complicate future
implementations of state serialization and deserialization.

### Architectural Improvements:
1. **Worker Architecture Cleanup**: The existing worker architecture has
evolved in an ad-hoc manner, leading to a lack of clarity. An example is
the Network Communicate Actor, which needs a redesign for better
maintainability.

### Current Worker Architecture
See the current architecture diagram here: ![Texera Overall
Infrastructure](https://github.com/Texera/texera/assets/13672781/22e4d48b-a687-4c50-abf7-0a4bff0cbb57)

## Key Refactorings in This PR
### Supporting Checkpoints:
1. **Message Class Unification**: Introduced a unified message type
`WorkflowFIFOMessage` with a `ChannelID` to clearly identify
communication channels, reducing code duplication.
2. **Actor Component Extraction**: Separated actor-related components
(like Actor context, timers, flow control and congestion control) from
DP, integrating them into the main actor for better alignment with the
Akka actor system and avoiding serialization.
3. **Core State Introduction**: Established a core state within the
actor(i.e. DataProcessor, AmberProcessor) for serialization during
checkpoints, ensuring non-core states are excluded from serialization
processes.

### Architectural Improvements:
1. **Network Communication Actor Removal**: Transferred all messaging
responsibilities to the main actor, including sending messages and
receiving acks. Flow and congestion controls have been refactored on a
per-channel basis.
2. **Renaming for Clarity**: Changed `NetworkInputPort` and
`NetworkOutputPort` to `NetworkInputGateway` and `NetworkOutputGateway`,
reflecting their roles in managing multiple channels.
3. **Enhanced Testing**: Added additional test cases for Java/Python
workers.

### Temporary Changes:
- The controller has been temporarily removed and end-to-end tests are
currently disabled. These will be reinstated in PR #2209.

### Post-Refactoring Worker Architecture
View the updated architecture diagram here: ![Refactored Worker
Architecture](https://github.com/Texera/texera/assets/13672781/b0b1d4f3-96e1-4ea9-aa57-bdde70ca2fdc)


### Flow control

After this PR, the credit of flow control is not sent back with the
acks. We poll from the downstream operator whenever the credit is not
enough. This will be fixed later with a new flow control design.

---------

Co-authored-by: Yicong Huang <17627829+Yicong-Huang@users.noreply.github.com>
yangzhang75 pushed a commit to yangzhang75/texera that referenced this pull request Jun 22, 2026
## Purpose of Refactoring
### Supporting Checkpoints:
1. **Channel Clarity and Message Handling**: Previously, the worker's
handling of messages in channels was ambiguous, using various message
classes to differentiate channels. This led to code duplication and
complexity for implementing checkpoints.
2. **State Management**: The components within a worker are
well-organized. This disorganization would complicate future
implementations of state serialization and deserialization.

### Architectural Improvements:
1. **Worker Architecture Cleanup**: The existing worker architecture has
evolved in an ad-hoc manner, leading to a lack of clarity. An example is
the Network Communicate Actor, which needs a redesign for better
maintainability.

### Current Worker Architecture
See the current architecture diagram here: ![Texera Overall
Infrastructure](https://github.com/Texera/texera/assets/13672781/22e4d48b-a687-4c50-abf7-0a4bff0cbb57)

## Key Refactorings in This PR
### Supporting Checkpoints:
1. **Message Class Unification**: Introduced a unified message type
`WorkflowFIFOMessage` with a `ChannelID` to clearly identify
communication channels, reducing code duplication.
2. **Actor Component Extraction**: Separated actor-related components
(like Actor context, timers, flow control and congestion control) from
DP, integrating them into the main actor for better alignment with the
Akka actor system and avoiding serialization.
3. **Core State Introduction**: Established a core state within the
actor(i.e. DataProcessor, AmberProcessor) for serialization during
checkpoints, ensuring non-core states are excluded from serialization
processes.

### Architectural Improvements:
1. **Network Communication Actor Removal**: Transferred all messaging
responsibilities to the main actor, including sending messages and
receiving acks. Flow and congestion controls have been refactored on a
per-channel basis.
2. **Renaming for Clarity**: Changed `NetworkInputPort` and
`NetworkOutputPort` to `NetworkInputGateway` and `NetworkOutputGateway`,
reflecting their roles in managing multiple channels.
3. **Enhanced Testing**: Added additional test cases for Java/Python
workers.

### Temporary Changes:
- The controller has been temporarily removed and end-to-end tests are
currently disabled. These will be reinstated in PR apache#2209.

### Post-Refactoring Worker Architecture
View the updated architecture diagram here: ![Refactored Worker
Architecture](https://github.com/Texera/texera/assets/13672781/b0b1d4f3-96e1-4ea9-aa57-bdde70ca2fdc)


### Flow control

After this PR, the credit of flow control is not sent back with the
acks. We poll from the downstream operator whenever the credit is not
enough. This will be fixed later with a new flow control design.

---------

Co-authored-by: Yicong Huang <17627829+Yicong-Huang@users.noreply.github.com>
renovate-bot pushed a commit to renovate-bot/apache-_-texera that referenced this pull request Jul 30, 2026
### What changes were proposed in this PR?

Deletes `OrderingEnforcer`, a generic helper in the amber engine with no
production caller. Pure deletion, no behaviour change: **−203 lines**.

| Removed | Lines | Why it is dead |
| --- | ---: | --- |
| `architecture/messaginglayer/OrderingEnforcer.scala` | 53 | last
caller removed by apache#2208 |
| `architecture/messaginglayer/OrderingEnforcerSpec.scala` | 150 |
covers only the above |

`OrderingEnforcer` was the extracted, generic form of the FIFO /
exactly-once reorder buffer. apache#2208 ("Refactoring of amber engine",
2023-11-15) inlined that logic into `AmberFIFOChannel`, which still
carries the identical header comment `/* The abstracted
FIFO/exactly-once logic */` and re-declares the same members:

```
OrderingEnforcer[T]  (deleted)        AmberFIFOChannel  (live, unchanged)
  ofoMap: LongMap[T]                    ofoMap: HashMap[Long, WorkflowFIFOMessage]
  current: Long                         current: Long
  isDuplicated / isAhead                isDuplicated / isAhead
  stash / enforceFIFO                   stash / enforceFIFO
```

The generic copy has been stranded for two and a half years.

> Reviewer note: there is a separate, **live** `OrderEnforcer` trait (no
`-ing`) in `architecture/logreplay/`, used by
`InputGateway`/`NetworkInputGateway`. It is unrelated and untouched —
only the `messaginglayer` `OrderingEnforcer` is removed here.

It acquired unit tests during the 2026 coverage work (apache#4721), which is
why it currently looks live despite having been unreachable since 2023.

**Scope change after review:** this PR originally also removed
`Utils.retry`. Per @Yicong-Huang's review it has been restored and is
untouched here — `Utils.scala` and `UtilsSpec.scala` are byte-identical
to `main`.

### Any related issues, documentation, discussions?

Closes apache#7027

### How was this PR tested?

Existing tests only — this PR adds none, since it removes code and the
spec that covered it.

Locally, from the repo root with Java 17:

- `sbt "scalafixAll --check"` — clean.
- `sbt scalafmtCheckAll` — clean.
- `sbt "WorkflowExecutionService/testOnly *UtilsSpec"` — 74 tests, all
pass (`Utils.retry` and its three tests are back and green).

Verification that nothing references the removed class, re-runnable by a
reviewer:

```
git grep -nw OrderingEnforcer      # only the two deleted files
```

### Was this PR authored or co-authored using generative AI tooling?

Generated-by: Claude Code (Claude Opus 5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

refactor Refactor the code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants