Harbor: Support for CockroachDB (don't use pg_advisory_lock)

Created on 13 Aug 2019  路  13Comments  路  Source: goharbor/harbor

Is your feature request related to a problem? Please describe.
We would like to use CockroachDB for a replicated / clustered database backend, possibily even for a multi-region setup of Harbor. Since CockroachDB speaks a dialect of PostgreSQL, this should be possible with some modifications.

The main issue with CockroachDB seems to be the lack of support for pg_advisory_lock() - CockroachDB will probably not support this function in the near future.

Describe the solution you'd like
Implement CockroachDB support, e.g. by solving #8511 and #6942 and drop pg_advisory_lock() calls (maybe via a flag / configuration option). I'm honestly not sure if that's possible, I just wanted to document the main issue with CockroachDB support that we encountered.

Describe the main design/architecture of your solution


Describe the development plan you've considered


Additional context

This is what Harbor Core logs when you configure CockroachDB as target:

2019-08-13T10:11:44Z [ERROR] [/common/dao/pgsql.go:112]: Failed to upgrade schema, error: "try lock failed in line 0: SELECT pg_advisory_lock($1) (details: pq: unknown function: pg_advisory_lock())" 
areHA kinrequirement

Most helpful comment

@embik @KarstenSiemer
Thanks a lot for raising this.

The error is thrown by the migrator, it seems it supports cockroach DB:
https://github.com/golang-migrate/migrate/tree/master/database/cockroachdb

We'll do some investigation to see if we can support that with minimal change in configuration.

All 13 comments

I'd highly suggest to put more effort into this if this is a highly requested feature.
Since Cockroach always uses SERIALIZABLE isolation instead of a locking kind mechanism the implementation will need some customizations to be of highest quality.
For anyone interested these sources will give you a quick intro:
Isolation in CockroachDB
Client-side Transaction Retries
Build a Java App with CockroachDB(JDBC or Hibernate)

@embik @KarstenSiemer

Thank you very much for raising the requirement to the Harbor community. We'll check and prioritize it based on the release plans and resources.

If you want to accelerate the progress, you guys can promote it in the community and get more supports from the community to improve the priority.

@embik @KarstenSiemer
Thanks a lot for raising this.

The error is thrown by the migrator, it seems it supports cockroach DB:
https://github.com/golang-migrate/migrate/tree/master/database/cockroachdb

We'll do some investigation to see if we can support that with minimal change in configuration.

Hi, we want also to use CockroachDB for Harbor as we have Harbor clusters in 5 DCs across the world, and CockroachDb DC will be a perfect solution to consolidate our data from all DCs in 1 table

I am in roughly the same position as @linux-wizard. There are numerous tools that all seem to want to follow their own pattern of putting a non-HA DB on a PVC. It isn't sustainable for everyone to follow this pattern from an operational perspective.

Many folks are very eager to adopt this solution. Being able to configure an external DB of various flavors is essential for production use cases.

From a quick read of https://github.com/goharbor/harbor/blob/master/src/common/dao/pgsql.go#L24, this could be replaced by the ditto cockroachdb migrator (+ some re-naming of postgres to cockroachdb).

But there is quite a bit of code in that module, and I haven't checked if any/how much is postgres/sqlite aware to begin with. (Though cockroachdb is a fairly close cousin of postgres, so most things should just work).

I'd love to see this implemented - running in Harbor in a pure-Kubernetes mode would be excellent, and the PostgreSQL dependency makes that unnecessarily complicated.

Same here, same arguments like @nyarly
+1

Agreed. A built-in HA kubernetes native option would be better than the external HA PostgreSQL.
+1

@reasonerjt Are you still working on this?

I think it would be better if someone can contribute PR first and do some basic verification, that would be great help to push the progress

+1

+1

Was this page helpful?
0 / 5 - 0 ratings

Related issues

cedvan picture cedvan  路  3Comments

pingcrosby picture pingcrosby  路  3Comments

a-kinder picture a-kinder  路  3Comments

xiaosadexiaohai picture xiaosadexiaohai  路  3Comments

andrewtchin picture andrewtchin  路  3Comments