Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

agd export option for diagnosis #10344

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open

agd export option for diagnosis #10344

wants to merge 19 commits into from

Conversation

usmanmani1122
Copy link
Contributor

@usmanmani1122 usmanmani1122 commented Oct 28, 2024

closes: #8420
ref: #8152

Description

This PR adds a new optional flag --swing-store-export-mode to the agd export command which can be used to specify the nature of swing-store export

Security Considerations

None

Scaling Considerations

None

Documentation Considerations

An optional flag --swing-store-export-mode option is now supported for agd export to specify the kind of swing store export required:

  • operational (default) option will retain the existing behavior and export the swing-store artifacts using the latest height
  • skip option will not export any swing-store artifact
  • debug option will export all swing-store artifacts, starting from height 0

Testing Considerations

Tested manually

Upgrade Considerations

None

@usmanmani1122 usmanmani1122 self-assigned this Oct 28, 2024
Copy link

cloudflare-workers-and-pages bot commented Oct 28, 2024

Deploying agoric-sdk with  Cloudflare Pages  Cloudflare Pages

Latest commit: 530a2b5
Status: ✅  Deploy successful!
Preview URL: https://7aa5b0e8.agoric-sdk.pages.dev
Branch Preview URL: https://usman-8420.agoric-sdk.pages.dev

View logs

}

// We don't have to launch VM in case the swing store export is not required
if !(swingStoreExportMode == swingsetkeeper.SwingStoreArtifactModeSkip || OnExportHook == nil) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mhofman since OnExportHook currently points to launchVM, is it okay to bypass this hook in case swing-store export is not needed? Or do you see us adding cosmic side future hook changes?

Copy link
Member

Choose a reason for hiding this comment

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

I think that's fine, but I'd like @michaelfig to confirm, especially with his upcoming changed for split brains. Basically export only needs to launch the VM if it will export the swing-store, which is decided by a command line config. Since OnExportHook is unconditionally set or not based on the entrypoint used, the only option we have is to ignore it here.

Copy link
Member

Choose a reason for hiding this comment

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

Btw, my brain still struggles with distributing negations.

Suggested change
if !(swingStoreExportMode == swingsetkeeper.SwingStoreArtifactModeSkip || OnExportHook == nil) {
if swingStoreExportMode != swingsetkeeper.SwingStoreArtifactModeSkip && OnExportHook != nil {

@usmanmani1122 usmanmani1122 marked this pull request as ready for review October 31, 2024 12:07
@usmanmani1122 usmanmani1122 requested a review from a team as a code owner October 31, 2024 12:07
artifactsEnded = true
if eventHandler.exportMode == keeper.SwingStoreArtifactModeDebug {
err = nil
exportDataReader, err := getExportDataReader()
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to close this reader in defer?
defer exportDataReader.Close()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought EncodeKVEntryReaderToJsonl function will close the reader passed to it at the end but it seems like it doesn't

Comment on lines 249 to 256
artifact = types.SwingStoreArtifact{
Data: encodedExportData.Bytes(),
Name: keeper.UntrustedExportDataArtifactName,
}
}
}
}
}
Copy link
Contributor

@Muneeb147 Muneeb147 Oct 31, 2024

Choose a reason for hiding this comment

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

So in-case exportMode is "debug", we are sending an extra artifact at the end which is a full export of swingStore (Kvstore)? Right? Assuming that caller iterates over ReadNextArtifact until gets io.EOF.

Copy link
Member

@mhofman mhofman left a comment

Choose a reason for hiding this comment

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

Thanks for digging through this. The main issue is that we don't currently write out the "export data" as "untrusted copy" in debug mode, but instead we-write the cosmos DB copy.

// genesis.json file.
// TODO: document this flag in config, likely alongside the genesis path
FlagSwingStoreExportDir = "swing-store-export-dir"
FlagSwingStoreExportMode = "swing-store-export-mode"
Copy link
Member

Choose a reason for hiding this comment

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

Let's add a godoc comment for this flag

Comment on lines 390 to 392
swingsetkeeper.SwingStoreArtifactModeDebug: true,
swingsetkeeper.SwingStoreArtifactModeOperational: true,
swingsetkeeper.SwingStoreArtifactModeSkip: true,
Copy link
Member

Choose a reason for hiding this comment

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

This is a bit of a hacky reuse, especially because skip is not a current artifact mode. It would be clearer to define explicit constants for the swing-store genesis export mode, describing what each one does.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are right. skip is not a supported artifact mode. I will revert SwingStoreArtifactModeSkip to SwingStoreArtifactModeNone.
But I don't see SwingStoreArtifactModeNone and SwingStoreArtifactModeDebug used elsewhere and I think they were defined for controlling the artifact mode. So why not use them?

Copy link
Member

Choose a reason for hiding this comment

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

It's more of a conceptual question. We're not just controlling the artifacts part of the swing-store export, but what kind of swing-store export we want to do. It happens that we're partially reusing the same words to describe the whole export, as the artifacts part if a bug component of it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

}

// We don't have to launch VM in case the swing store export is not required
if !(swingStoreExportMode == swingsetkeeper.SwingStoreArtifactModeSkip || OnExportHook == nil) {
Copy link
Member

Choose a reason for hiding this comment

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

I think that's fine, but I'd like @michaelfig to confirm, especially with his upcoming changed for split brains. Basically export only needs to launch the VM if it will export the swing-store, which is decided by a command line config. Since OnExportHook is unconditionally set or not based on the entrypoint used, the only option we have is to ignore it here.

}

// We don't have to launch VM in case the swing store export is not required
if !(swingStoreExportMode == swingsetkeeper.SwingStoreArtifactModeSkip || OnExportHook == nil) {
Copy link
Member

Choose a reason for hiding this comment

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

Btw, my brain still struggles with distributing negations.

Suggested change
if !(swingStoreExportMode == swingsetkeeper.SwingStoreArtifactModeSkip || OnExportHook == nil) {
if swingStoreExportMode != swingsetkeeper.SwingStoreArtifactModeSkip && OnExportHook != nil {

snapshotHeight,
eventHandler,
keeper.SwingStoreExportOptions{
ArtifactMode: swingStoreExportMode,
Copy link
Member

Choose a reason for hiding this comment

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

I would prefer to set above a artifactMode := swingStoreExportMode and explain that the values for this option currently matches for non skip.

if err == io.EOF {
artifactsEnded = true
if eventHandler.exportMode == keeper.SwingStoreArtifactModeDebug {
exportDataReader, _ := getExportDataReader()
Copy link
Member

Choose a reason for hiding this comment

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

This should come from the swing-store export (aka provider.GetExportDataReader()).

Copy link
Contributor Author

@usmanmani1122 usmanmani1122 Nov 11, 2024

Choose a reason for hiding this comment

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

Yes. My bad. Not sure why I changed it in this commit 😄

Comment on lines +244 to +253
err = agoric.EncodeKVEntryReaderToJsonl(
exportDataReader,
&encodedExportData,
)
if err == nil {
artifact = types.SwingStoreArtifact{
Data: encodedExportData.Bytes(),
Name: keeper.UntrustedExportDataArtifactName,
}
}
Copy link
Member

Choose a reason for hiding this comment

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

It really is a bit unfortunate we have to read, decode, re-encode it all in memory before finally writing it out, but streamlining this is definitely out of scope.

@@ -160,7 +160,7 @@ type swingStoreRestoreExportAction struct {
const (
// SwingStoreArtifactModeNone means that no artifacts are part of the
// export / import.
SwingStoreArtifactModeNone = "none"
SwingStoreArtifactModeSkip = "skip"
Copy link
Member

Choose a reason for hiding this comment

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

I very much would like to not change this as it matches cosmic-swingset definitions

return nil
}), nil
}

artifactsProvider := keeper.SwingStoreExportProvider{
Copy link
Member

Choose a reason for hiding this comment

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

In the case of debug mode (and only in this case), the export artifact should capture the blockHeight of the swing-store, so we don't completely lose track of it (we unfortunately don't have a better place to stash it)

if eventHandler.exportMode == keeper.SwingStoreArtifactModeDebug {
  artifactProvider.BlockHeight = provider.BlockHeight
}

Comment on lines 201 to 202
if !((eventHandler.exportMode == keeper.SwingStoreArtifactModeDebug && eventHandler.snapshotHeight == 0) ||
eventHandler.snapshotHeight == provider.BlockHeight) {
Copy link
Member

Choose a reason for hiding this comment

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

Part of this check is technically redundant

Suggested change
if !((eventHandler.exportMode == keeper.SwingStoreArtifactModeDebug && eventHandler.snapshotHeight == 0) ||
eventHandler.snapshotHeight == provider.BlockHeight) {
if eventHandler.exportMode != keeper.SwingStoreArtifactModeDebug &&
eventHandler.snapshotHeight != provider.BlockHeight {

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.

agd export option for diagnosis
3 participants