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

Lvol snapshot management of User Created flag #106

Closed
wants to merge 4 commits into from

Conversation

DamiaSan
Copy link
Contributor

@DamiaSan DamiaSan commented Feb 5, 2024

Which issue(s) this PR fixes:

Issue #7578

What this PR does / why we need it:

Special notes for your reviewer:

Additional documentation or context

Longhorn 7578

Signed-off-by: Damiano Cipriani <[email protected]>
shuo-wu
shuo-wu previously approved these changes Feb 5, 2024
Copy link
Contributor

@shuo-wu shuo-wu left a comment

Choose a reason for hiding this comment

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

The UserCreated flag modification LGTM.
But the vendor update introduced xattrs SnapshotTime as well. We need to add it for ReplicaSnapshotCreate so that one snapshot has the same timestamp among all replicas. Besides, for snapshots, the creation time should be loaded from the xattrs instead.

@DamiaSan
Copy link
Contributor Author

DamiaSan commented Feb 5, 2024

The UserCreated flag modification LGTM. But the vendor update introduced xattrs SnapshotTime as well. We need to add it for ReplicaSnapshotCreate so that one snapshot has the same timestamp among all replicas. Besides, for snapshots, the creation time should be loaded from the xattrs instead.

Yes, I agree with you. We will make the development for SnapshotTimestamp in another PR, now let's merge this one so we can update longhorn-instance-manager and close the UserCreated issue.

@DamiaSan
Copy link
Contributor Author

DamiaSan commented Feb 6, 2024

@innobead @derekbit @shuo-wu I don't have the permission to merge this PR. Who can make it?

@innobead
Copy link
Member

innobead commented Feb 6, 2024

@innobead @derekbit @shuo-wu I don't have the permission to merge this PR. Who can make it?

You have write permission, so should be able to merge it 🤔 Wait, I will review this later first before merging. Thanks.

return err
}

func (e *Engine) snapshotOperation(spdkClient *spdkclient.Client, inputSnapshotName string, snapshotOp SnapshotOperationType) (snapshotName string, err error) {
func (e *Engine) snapshotOperation(spdkClient *spdkclient.Client, inputSnapshotName string, snapshotOp SnapshotOperationType, opts util.SnapshotOptions) (snapshotName string, err error) {
Copy link
Member

Choose a reason for hiding this comment

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

Suggest just use opts *SnapshotOptions to prevent unnecessary obj copy. This suggestion is for all changed methods.

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

@@ -835,6 +847,9 @@ func (r *Replica) SnapshotCreate(spdkClient *spdkclient.Client, snapshotName str
return nil, fmt.Errorf("zero or multiple snap lvols with UUID %s found after lvol snapshot", snapUUID)
}

if userCreatedFlag {
bdevLvolList[0].DriverSpecific.Lvol.Xattrs[spdkclient.UserCreated] = "true"
}
Copy link
Member

Choose a reason for hiding this comment

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

Why do we need this? This should be implemented in BdevLvolGet already.

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

pkg/util/util.go Outdated
@@ -22,6 +22,10 @@ import (
"github.com/longhorn/go-common-libs/proc"
)

type SnapshotOptions struct {
UserCreated bool
}
Copy link
Member

Choose a reason for hiding this comment

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

Suggest moving this to pkg/spdk/typges.go instead? Adding this to a common util package seems not intuitive to me.

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

UserCreated: req.UserCreated,
}

snapshotName, err := e.SnapshotCreate(spdkClient, req.SnapshotName, opts)
Copy link
Member

Choose a reason for hiding this comment

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

Why don't we use the same way for both replica and engine snapshot call? The engine call is using an option struct, but the replica call is just using a bool parameter.

return r.SnapshotCreate(spdkClient, req.SnapshotName, req.UserCreated)

Can we just make them consistent?

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

pkg/client/client.go Outdated Show resolved Hide resolved
pkg/spdk/engine.go Show resolved Hide resolved
@@ -1427,7 +1440,7 @@ func (r *Replica) RebuildingDstSnapshotCreate(spdkClient *spdkclient.Client, sna
}()

snapLvolName := GetReplicaSnapshotLvolName(r.Name, snapshotName)
snapUUID, err := spdkClient.BdevLvolSnapshot(r.rebuildingLvol.UUID, snapLvolName)
snapUUID, err := spdkClient.BdevLvolSnapshot(r.rebuildingLvol.UUID, snapLvolName, nil)
Copy link
Contributor

Choose a reason for hiding this comment

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

We should add opts for this API input then put it here.

Copy link
Contributor

Choose a reason for hiding this comment

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

Remember to update this.
This API will be invoked by the engine rebuilding here. The engine should check the flag of each snapshot then input the opts correct for RebuildingDstSnapshotCreate invocation

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry but I don't understand well what you are asking to me. If this API is invoked by the engine during the rebuild, the snapshot is not a user created snapshot ans so there is no necessity to pass opts here.

Copy link
Contributor

@shuo-wu shuo-wu Feb 21, 2024

Choose a reason for hiding this comment

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

This function copies all snapshots from a healthy replica to the new replica. If a snapshot was ever requested by users, this snapshot should contain the attribute userCreated: true for all replicas.
In other words, the tag user created means if the snapshot CR of the volume is requested by the users themselves. It does not stand for the snapshot file in a specific replica being created by API SnapshotCreate or rebuilt from other replicas.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok thanks, I will add this

pkg/spdk/replica.go Show resolved Hide resolved
Longhorn 7578

Signed-off-by: Damiano Cipriani <[email protected]>
@DamiaSan
Copy link
Contributor Author

DamiaSan commented Feb 8, 2024

Codespell is returning the following error:
Error: ./proto/vendor/protobuf/src/google/protobuf/empty.proto:43: re-use ==> reuse
It is a comment, what should I do? Modify this file?

@innobead
Copy link
Member

innobead commented Feb 8, 2024

Codespell errro is fine. Just skip it.

@DamiaSan
Copy link
Contributor Author

DamiaSan commented Feb 8, 2024

Codespell errro is fine. Just skip it.

So, once you will have resolved the requested changes (I have already addressed all of them), the PR can be merged also with codespell errors?

@innobead
Copy link
Member

innobead commented Feb 8, 2024

Yes. However, we will fix the codespell setting later.

@@ -1427,7 +1440,7 @@ func (r *Replica) RebuildingDstSnapshotCreate(spdkClient *spdkclient.Client, sna
}()

snapLvolName := GetReplicaSnapshotLvolName(r.Name, snapshotName)
snapUUID, err := spdkClient.BdevLvolSnapshot(r.rebuildingLvol.UUID, snapLvolName)
snapUUID, err := spdkClient.BdevLvolSnapshot(r.rebuildingLvol.UUID, snapLvolName, nil)
Copy link
Contributor

Choose a reason for hiding this comment

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

Remember to update this.
This API will be invoked by the engine rebuilding here. The engine should check the flag of each snapshot then input the opts correct for RebuildingDstSnapshotCreate invocation

@innobead
Copy link
Member

@DamiaSan is this PR ready?

Copy link

mergify bot commented Feb 21, 2024

This pull request is now in conflict. Could you fix it @DamiaSan? 🙏

@DamiaSan
Copy link
Contributor Author

I am going to close this PR and will make a new one.

@DamiaSan DamiaSan closed this Feb 22, 2024
@DamiaSan DamiaSan mentioned this pull request Feb 22, 2024
@DamiaSan
Copy link
Contributor Author

#115

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