Skip to content

Conversation

@stdpain
Copy link
Contributor

@stdpain stdpain commented Dec 26, 2025

Why I'm doing:

StarRocks currently features a plugin mechanism that enables users to install and manage plugins via SQL, such as audit log plugins or data integration plugins.
However, the existing plugin mechanism primarily focuses on plugin installation/uninstallation and single-function implementation. It lacks the capability for deep extension into internal system behaviors and cannot uniformly manage plugin lifecycles, dependencies, and resources. This makes it difficult to meet more complex business scenarios and expansion requirements.

What I'm doing:

  1. introduce an auto load extension framework
  2. refactor GsonUtil

What type of PR is this:

  • BugFix
  • Feature
  • Enhancement
  • Refactor
  • UT
  • Doc
  • Tool

Does this PR entail a change in behavior?

  • Yes, this PR will result in a change in behavior.
  • No, this PR will not result in a change in behavior.

If yes, please specify the type of change:

  • Interface/UI changes: syntax, type conversion, expression evaluation, display information
  • Parameter changes: default values, similar parameters but with different default values
  • Policy changes: use new policy to replace old one, functionality automatically enabled
  • Feature removed
  • Miscellaneous: upgrade & downgrade compatibility, etc.

Checklist:

  • I have added test cases for my bug fix or my new feature
  • This pr needs user documentation (for new or modified features or behaviors)
    • I have added documentation for my new feature or new function
    • This pr needs auto generate documentation
  • This is a backport pr

Bugfix cherry-pick branch check:

  • I have checked the version labels which the pr will be auto-backported to the target branch
    • 4.0
    • 3.5
    • 3.4
    • 3.3

Note

Adds a lightweight extension system and decouples Gson configuration.

  • Introduces ExtensionManager, SRModule, StarRocksExtension, and scanners (JarScanner, DirectoryClassPathScanner) to auto-load extensions; FE now calls ExtensionManager.loadExtensionsFromDir(Config.ext_dir) at startup
  • New Config key ext_dir (defaults to $STARROCKS_HOME/lib)
  • Adds DefaultExtensionContext providing defaults (WarehouseManager, ResourceUsageMonitor, BaseSlotManager via SlotManager, IGsonBuilderFactory)
  • GlobalStateMgr now obtains WarehouseManager, ResourceUsageMonitor, and BaseSlotManager from ExtensionManager instead of direct instantiation
  • Refactors Gson: new IGsonBuilderFactory and DefaultGsonBuilderFactory; moves adapters into persist.gson.internal/*; GsonUtils delegates builder creation to the factory
  • UT bootstrap (UtFrameUtils) loads extensions from classpath (target/classes)

Written by Cursor Bugbot for commit 25e3917. This will update automatically on new commits. Configure here.

@stdpain stdpain requested review from a team as code owners December 26, 2025 05:03
StarRocks currently features a plugin mechanism that enables users to install and manage plugins via SQL, such as audit log plugins or data integration plugins.
However, the existing plugin mechanism primarily focuses on plugin installation/uninstallation and single-function implementation. It lacks the capability for deep extension into internal system behaviors and cannot uniformly manage plugin lifecycles, dependencies, and resources. This makes it difficult to meet more complex business scenarios and expansion requirements.

Signed-off-by: stdpain <[email protected]>
@sonarqubecloud
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
1 Security Hotspot
C Reliability Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

@gengjun-git
Copy link
Contributor

gengjun-git commented Dec 26, 2025

Better to add docs to describe

  1. What is extension used for.
  2. how to add extension.

@github-actions
Copy link

[Java-Extensions Incremental Coverage Report]

pass : 0 / 0 (0%)

@github-actions
Copy link

[FE Incremental Coverage Report]

pass : 490 / 535 (91.59%)

file detail

path covered_line new_line coverage not_covered_line_detail
🔵 com/starrocks/StarRocksFEServer.java 0 1 00.00% [129]
🔵 com/starrocks/extension/DirectoryClassPathScanner.java 16 30 53.33% [40, 49, 50, 67, 68, 75, 77, 78, 79, 80, 82, 83, 84, 85]
🔵 com/starrocks/extension/ExtensionManager.java 20 30 66.67% [55, 56, 57, 60, 61, 63, 64, 65, 66, 67]
🔵 com/starrocks/persist/gson/internal/GuavaMultimapAdapter.java 23 32 71.88% [58, 59, 89, 90, 92, 93, 95, 96, 98]
🔵 com/starrocks/extension/JarScanner.java 25 30 83.33% [37, 43, 49, 50, 72]
🔵 com/starrocks/extension/DefaultExtensionContext.java 15 17 88.24% [37, 46]
🔵 com/starrocks/persist/gson/DefaultGsonBuilderFactory.java 26 27 96.30% [82]
🔵 com/starrocks/persist/gson/internal/RangeAdapter.java 34 35 97.14% [70]
🔵 com/starrocks/persist/gson/internal/GuavaTableAdapter.java 59 60 98.33% [126]
🔵 com/starrocks/persist/gson/internal/RuntimeTypeAdapterTypes.java 227 228 99.56% [181]
🔵 com/starrocks/common/Config.java 1 1 100.00% []
🔵 com/starrocks/persist/gson/internal/MapTypeDeserializer.java 7 7 100.00% []
🔵 com/starrocks/server/GlobalStateMgr.java 3 3 100.00% []
🔵 com/starrocks/persist/gson/internal/PrimitiveTypeDeserializer.java 4 4 100.00% []
🔵 com/starrocks/persist/gson/internal/ColumnIdAdapter.java 3 3 100.00% []
🔵 com/starrocks/persist/gson/internal/StructTypeDeserializer.java 11 11 100.00% []
🔵 com/starrocks/persist/gson/GsonUtils.java 1 1 100.00% []
🔵 com/starrocks/persist/gson/internal/ProcessHookTypeAdapterFactory.java 15 15 100.00% []

@github-actions
Copy link

[BE Incremental Coverage Report]

pass : 0 / 0 (0%)

@stdpain
Copy link
Contributor Author

stdpain commented Dec 26, 2025

Better to add docs to describe

  1. What is extension used for.
  2. how to add extension.

see #67270

// See the License for the specific language governing permissions and
// limitations under the License.

package com.starrocks.extension;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to move this extension to a new module like fe/fe-extension ?

@alvin-celerdata
Copy link
Contributor

@cursor review

}
}
return classes;
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

URLClassLoader closed before extension classes can load dependencies

The URLClassLoader in scanJar() is closed via try-with-resources at line 75, but the loaded classes are returned and later instantiated in ExtensionManager.loadExtensions(). When the extension's constructor or onLoad() method tries to use other classes from the same JAR that weren't already loaded during scanning, class loading will fail because the classloader is closed. The URLClassLoader needs to remain open for the lifetime of the extension, or all required classes must be loaded before closing.

Additional Locations (1)

Fix in Cursor Fix in Web

String normalized =
classFile.toString().replace(File.separatorChar, '/');
return BASE_PACKAGES.stream().anyMatch(normalized::contains);
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Package filter uses dots but path uses slashes

The isUnderBasePackage() method compares file paths (which use slashes like com/starrocks/extension) against BASE_PACKAGES which use dot notation (like com.starrocks.extension). The normalized.contains() check will never match because "path/com/starrocks/extension/Class.class".contains("com.starrocks.extension") returns false due to the slash vs dot mismatch. This causes the scanner to filter out all class files, preventing any extensions from being discovered.

Fix in Cursor Fix in Web

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants