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

feat: Add etcd database support #1023

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

Conversation

hudeng-go
Copy link

@hudeng-go hudeng-go commented Feb 8, 2022

improve concurrent access and high availability of aptly with the help of the characteristics of etcd

Fixes #

Requirements

All new code should be covered with tests, documentation should be updated. CI should pass.

Description of the Change

Checklist

  • unit-test added (if change is algorithm)
  • functional test added/updated (if change is functional)
  • man page updated (if applicable)
  • bash completion updated (if applicable)
  • documentation updated
  • author name in AUTHORS

@hudeng-go
Copy link
Author

@lbolla Resolve system test errors at #1022

@lbolla
Copy link
Contributor

lbolla commented Feb 8, 2022

@hudeng-go Looking good to me. What do you think of this comment on the other ticket? #1022 (comment)

@@ -0,0 +1,175 @@
#!/usr/bin/env python
Copy link
Contributor

Choose a reason for hiding this comment

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

This script is almost identical to system/run.py:

/tmp/aptly etcd-dev ❯ diff system/run.py system/run-etcd.py
97a98,100
>                     t.configOverride = {
>                         "databaseEtcd": "127.0.0.1:2379"
>                     }

It would be much better to have a flag or an env variable to tell the test runner script to use etcd, rather than duplicate the whole script.

Moreover, I suspect that using configOverride may not work on all cases. Many unittests set their own overrides, so either they will be overwritten with the databaseEtcd key or viceversa.

Maybe databaseEtcd could come from the environment, e.g. APTLY_ETCD_DATABASE and set in lib.py:BaseTest.config dictionary?

@hudeng-go hudeng-go force-pushed the etcd-dev branch 2 times, most recently from b7b80fd to 30c5016 Compare February 10, 2022 06:57
system/lib.py Outdated
@@ -142,6 +142,7 @@ class BaseTest(object):
"gpgDisableSign": False,
"ppaDistributorID": "ubuntu",
"ppaCodename": "",
"databaseEtcd": "%s" % os.environ["APTLY_ETCD_DATABASE"],
Copy link
Contributor

Choose a reason for hiding this comment

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

This will throw a KeyError if the env var is not set, which it isn't in the normal system-tests. Maybe use os.environ.get("APTLY_ETCD_DATABASE") or "" to make sure we have a valid value in the config?

@@ -287,7 +288,12 @@ func (context *AptlyContext) _database() (database.Storage, error) {
if context.database == nil {
var err error

context.database, err = goleveldb.NewDB(context.dbPath())
if context.config().DatabaseEtcd != "" {
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if we should have a more explicit way to pick the database, rather than look at DatabaseEtcd.

Maybe having a new config like databaseBackend to be one of: "leveldb", "etcd", etc.? What do you think?

@lbolla
Copy link
Contributor

lbolla commented Feb 10, 2022

@hudeng-go Tests failed... https://github.com/aptly-dev/aptly/runs/5140408342?check_suite_focus=true
They also log a lot and take quite a long time, which will eat our free allowance of GH actions... Can you think of a solution?

@hudeng-go
Copy link
Author

@hudeng-go Tests failed... https://github.com/aptly-dev/aptly/runs/5140408342?check_suite_focus=true They also log a lot and take quite a long time, which will eat our free allowance of GH actions... Can you think of a solution?

Sorry, it took a long time to link etcd when migrating data. We are looking for the reason.

@lbolla
Copy link
Contributor

lbolla commented Feb 11, 2022

@hudeng-go I had to stop the CI once again, as it was stuck... Can we make the script so that it would crash at the first error, so we don't continue a clearly failing test?

@hudeng-go
Copy link
Author

@hudeng-go I had to stop the CI once again, as it was stuck... Can we make the script so that it would crash at the first error, so we don't continue a clearly failing test?

I have modified the migration script to exit with an error. Sorry again.

@hudeng-go
Copy link
Author

@hudeng-go I had to stop the CI once again, as it was stuck... Can we make the script so that it would crash at the first error, so we don't continue a clearly failing test?

In my environment, data can be migrated to normally. I don't know why I can't connect to etcd database in GH action environment.

Makefile Outdated Show resolved Hide resolved
if context.config().DatabaseBackend.Type == "etcd" {
context.database, err = etcddb.NewDB(context.config().DatabaseBackend.Url)
} else {
context.database, err = goleveldb.NewDB(context.dbPath())
Copy link
Contributor

Choose a reason for hiding this comment

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

I see the reason for using DatabaseBackend.Type as recommended. I wonder though if we can adapt dbPath (i.e. rootPath/db) into your new DbConfig structure? We must be backward compatible though. Maybe it's worth raising a separate ticket once this is merged.

Copy link
Author

Choose a reason for hiding this comment

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

I don't quite understand. At present, this dbpath should be available only for leveldb, and the current processing method should be compatible with it. My idea is that if the dbconfig configuration in the configuration file is empty, the default leveldb is used as the back-end, and leveldb compatibility should not be required in dbconfig. This is also explained in the man document.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, if we want to be backward compatible that's fine. I was considering the opportunity to fit the current dbPath behavior in your struct, too, to be "future-proof" (so in the future we can deprecate dbPath and just stay with your struct implementation). Food for though.

@lbolla
Copy link
Contributor

lbolla commented Feb 12, 2022

@hudeng-go I had to stop the CI once again, as it was stuck... Can we make the script so that it would crash at the first error, so we don't continue a clearly failing test?

Once #1033 is merged, you can rebase to ensure we have stricter timeouts for CI jobs, and avoid tests wasting our GHA allowance.

@lbolla
Copy link
Contributor

lbolla commented Feb 13, 2022

@hudeng-go I had to stop the CI once again, as it was stuck... Can we make the script so that it would crash at the first error, so we don't continue a clearly failing test?

Once #1033 is merged, you can rebase to ensure we have stricter timeouts for CI jobs, and avoid tests wasting our GHA allowance.

#1033 is merged. Please rebase this branch before carrying out further tests. Thanks!

@lbolla
Copy link
Contributor

lbolla commented Feb 14, 2022

@hudeng-go On my humble LXD image, which I use for development, etcd is using quite a lot of resources. Maybe it crashes on CI because it's too memory/cpu hungry?
Screenshot from 2022-02-14 14-09-04

@hudeng-go hudeng-go force-pushed the etcd-dev branch 2 times, most recently from ae5456d to 1122a66 Compare February 18, 2022 02:42
improve concurrent access and high availability of aptly with the help of the characteristics of etcd
databaseBackend config contains type and url sub config, It can facilitate the expansion of other types of databases in the future.
@tomsiewert
Copy link

Is there any update to bring this patch into upstream?

@tonobo
Copy link

tonobo commented Apr 19, 2023

Howdy, any chance to get this back on track?

@tomsiewert
Copy link

@randombenj As you seem to be the most active reviewer/contributor for Aptly, could you please review this?

@neolynx
Copy link
Member

neolynx commented Dec 1, 2023

Hi all,

maybe we should rebase this on master first, which seems to be a bit of work.. any chance someone could help with this ?

@neolynx neolynx self-assigned this Jan 14, 2024
@neolynx neolynx mentioned this pull request Apr 21, 2024
6 tasks
@neolynx
Copy link
Member

neolynx commented Jun 1, 2024

Hi all,

could aomeone have a look at why the test is running into a timeout in #1284 ?

@tomsiewert @tonobo @hudeng-go ?

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

Successfully merging this pull request may close these issues.

None yet

5 participants