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

Corrected the logic for calculating the expiration no of days #4451

Merged
merged 2 commits into from
Jan 23, 2023

Conversation

shtripat
Copy link
Contributor

@shtripat shtripat commented Jan 23, 2023

Description

Earlier ILM rule's set value of expiration days was getting deducted from current time and so the final value of no of days to expiration was coming as a -ve value (as expiration day would be in future and deducting from current day would result into a -ve value). Reversed the order of arguments to subtract function and works as expected.

Now the corrected output of command mc ilm rule ls <minio-cluster-name>/<bucket-name> looks as below

┌────────────────────────────────────────────────────────────────────────────────┐
│ Expiration for latest version (Expiration)                                     │
├───────────────┬─────────┬────────┬──────┬────────────────┬─────────────────────┤
│ ID            │ STATUS  │ PREFIX │ TAGS │ DAYS TO EXPIRE │ EXPIRE DELETEMARKER │
├───────────────┼─────────┼────────┼──────┼────────────────┼─────────────────────┤
│ expire-bucket │ Enabled │ -      │ -    │             23 │ false               │
└───────────────┴─────────┴────────┴──────┴────────────────┴─────────────────────┘

Motivation and Context

fixes bug #4446

How to test this PR?

Follow the below steps to test the PR
Step-1: Create a bucket using minio console
Step-2: Set the ilm rule using below command

mc ilm import minio/102938-4-300 <<EOF
{
"Rules": [
{
"Expiration": {
"Date": "2023-02-16T00:00:00Z"
},
"ID": "expire-bucket",
"Status": "Enabled"
}
]
}
EOF

Step-3: Check the minio console to see if rule gets listed as enabled
Step-4: Verify the changes using mc command mc ilm rule ls myminio/102938-4-300. The output should be as below

┌────────────────────────────────────────────────────────────────────────────────┐
│ Expiration for latest version (Expiration)                                     │
├───────────────┬─────────┬────────┬──────┬────────────────┬─────────────────────┤
│ ID            │ STATUS  │ PREFIX │ TAGS │ DAYS TO EXPIRE │ EXPIRE DELETEMARKER │
├───────────────┼─────────┼────────┼──────┼────────────────┼─────────────────────┤
│ expire-bucket │ Enabled │ -      │ -    │             23 │ false               │
└───────────────┴─────────┴────────┴──────┴────────────────┴─────────────────────┘

``

## Types of changes
- [x] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Optimization (provides speedup with no functional changes)
- [ ] Breaking change (fix or feature that would cause existing functionality to change)

## Checklist:
- [ ] Fixes a regression (If yes, please add `commit-id` or `PR #` here)
- [ ] Unit tests added/updated
- [ ] Internal documentation updated
- [ ] Create a documentation update request [here](https://github.com/minio/docs/issues/new?label=doc-change,title=Doc+Updated+Needed+For+PR+github.com%2fminio%2fmc%2fpull%2fNNNNN)

Earlier ILM rule' set value of expiration days was getting deducted from
current time and so the final value of no of days to expiration was coming
as a -ve value (as expiration day would be in future and deducting from current
day would result into a -ve value). Reversed the order of arguments to subtract
function and works as expected.

Now the corrected output of command `mc ilm rule ls <minio-cluster-name>/<bucket-name>`
looks as below

```
┌────────────────────────────────────────────────────────────────────────────────┐
│ Expiration for latest version (Expiration)                                     │
├───────────────┬─────────┬────────┬──────┬────────────────┬─────────────────────┤
│ ID            │ STATUS  │ PREFIX │ TAGS │ DAYS TO EXPIRE │ EXPIRE DELETEMARKER │
├───────────────┼─────────┼────────┼──────┼────────────────┼─────────────────────┤
│ expire-bucket │ Enabled │ -      │ -    │             23 │ false               │
└───────────────┴─────────┴────────┴──────┴────────────────┴─────────────────────┘
```

Signed-off-by: Shubhendu Ram Tripathi <shubhendu@minio.io>
cmd/ilm/utils.go Outdated Show resolved Hide resolved
Copy link
Contributor

@klauspost klauspost left a comment

Choose a reason for hiding this comment

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

LGTM

@harshavardhana harshavardhana merged commit 468fc49 into minio:master Jan 23, 2023
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.

None yet

3 participants