Re: [HACKERS] Satisfy extension dependency by one of multiple extensions

2011-09-24 Thread Dimitri Fontaine
Yeb Havinga yebhavi...@gmail.com writes:
 We might want to have a system where an extension can declare that it
 provides capabilites, and then have another extension require those
 capabilities. That would be a neater solution to the case that there are
 multiple extensions that all provide the same capability.

+1

 Yes that would be neater. I can't think of anything else however than to add
 extprovides' to pg_extension, fill it with an explicit 'provides' from the
 control file when present, or extname otherwise, and use that column to
 check the 'requires' list on extension creation time.

That sounds like a good rough plan.

Then we need to think about maintenance down the road, some releases
from now we will need more features around the same topic.  Debian
control file also has Conflicts and Replaces entries, so that using the
three of them you can handle a smooth upgrade even when the extension
changed its name or has been superseded by a new one which often has the
advantage of being maintained.

Regards,
-- 
Dimitri Fontaine
http://2ndQuadrant.fr PostgreSQL : Expertise, Formation et Support

-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] Satisfy extension dependency by one of multiple extensions

2011-09-24 Thread Joshua Berkus
All,

  We might want to have a system where an extension can declare that
  it
  provides capabilites, and then have another extension require
  those
  capabilities. That would be a neater solution to the case that
  there are
  multiple extensions that all provide the same capability.
 
 +1

As a warning, this is the sort of thing which DEB and RPM have spent years 
implementing ... and still have problems with.  Not that we shouldn't do it, 
but we should be prepared for the amount of troubleshooting involved, which 
will be considerable.

--Josh Berkus



-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


[HACKERS] Satisfy extension dependency by one of multiple extensions

2011-09-23 Thread Yeb Havinga

Hello list,

I have a use case where an extension dependency can be satisfied by one 
of five other extensions. Currently I'm unable to express that in the 
extension control file, since the elements from 'requires' are currently 
searched on exact name match. The attached patch changes this behaviour 
for list elements that end with a *, into prefix matching, so that e.g. 
table* matches tablefunc.


This allows me to specify in a controlfile

requires 'vocab*'

which is satisfied by having either one of the following extensions loaded:

vocab2005
vocab2006
vocab2008
vocab2009
vocab2010

thoughts?

regards,
Yeb Havinga

--
Yeb Havinga
http://www.mgrid.net/
Mastering Medical Data

diff --git a/src/backend/commands/extension.c b/src/backend/commands/extension.c
new file mode 100644
index 278bbcf..5bf7f8e
*** a/src/backend/commands/extension.c
--- b/src/backend/commands/extension.c
*** static void ApplyExtensionUpdates(Oid ex
*** 114,145 
  Oid
  get_extension_oid(const char *extname, bool missing_ok)
  {
! 	Oid			result;
! 	Relation	rel;
  	SysScanDesc scandesc;
  	HeapTuple	tuple;
  	ScanKeyData entry[1];
  
  	rel = heap_open(ExtensionRelationId, AccessShareLock);
  
  	ScanKeyInit(entry[0],
  Anum_pg_extension_extname,
! BTEqualStrategyNumber, F_NAMEEQ,
  CStringGetDatum(extname));
  
! 	scandesc = systable_beginscan(rel, ExtensionNameIndexId, true,
!   SnapshotNow, 1, entry);
  
! 	tuple = systable_getnext(scandesc);
  
! 	/* We assume that there can be at most one matching tuple */
! 	if (HeapTupleIsValid(tuple))
! 		result = HeapTupleGetOid(tuple);
! 	else
! 		result = InvalidOid;
  
! 	systable_endscan(scandesc);
  
  	heap_close(rel, AccessShareLock);
  
  	if (!OidIsValid(result)  !missing_ok)
--- 114,152 
  Oid
  get_extension_oid(const char *extname, bool missing_ok)
  {
! 	Oid			result   = InvalidOid;
! 	Relation	rel, idx;
  	SysScanDesc scandesc;
  	HeapTuple	tuple;
  	ScanKeyData entry[1];
+ 	int len  = strlen(extname) - 1;
+ 	boolwildcard = (extname[len] == '*');
  
  	rel = heap_open(ExtensionRelationId, AccessShareLock);
+ 	idx = index_open(ExtensionNameIndexId, AccessShareLock);
  
  	ScanKeyInit(entry[0],
  Anum_pg_extension_extname,
! BTGreaterEqualStrategyNumber,
! F_NAMEGE,
  CStringGetDatum(extname));
  
! 	scandesc = systable_beginscan_ordered(rel, idx,
! 		  SnapshotNow, 1, entry);
  
! 	if (HeapTupleIsValid(tuple = systable_getnext_ordered(scandesc, ForwardScanDirection)))
! 	{
! 		Form_pg_extension form = (Form_pg_extension) GETSTRUCT(tuple);
  
! 		if (wildcard
! 			? (strncmp(extname, NameStr(form-extname), len) == 0)
! 			: (strcmp(extname, NameStr(form-extname)) == 0))
! 			result = HeapTupleGetOid(tuple);
! 	}
  
! 	systable_endscan_ordered(scandesc);
  
+ 	index_close(idx, AccessShareLock);
  	heap_close(rel, AccessShareLock);
  
  	if (!OidIsValid(result)  !missing_ok)

-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] Satisfy extension dependency by one of multiple extensions

2011-09-23 Thread Heikki Linnakangas

On 23.09.2011 14:56, Yeb Havinga wrote:

I have a use case where an extension dependency can be satisfied by one
of five other extensions. Currently I'm unable to express that in the
extension control file, since the elements from 'requires' are currently
searched on exact name match. The attached patch changes this behaviour
for list elements that end with a *, into prefix matching, so that e.g.
table* matches tablefunc.


That's going to quickly extend into even more complex rules, like foo 
OR bar, (foo OR bar) AND (foobar) etc. IIRC the extension control 
file format was modeled after some other package management system (.deb 
?). You might want to look at the past discussions when the extension 
control file format was decided.


We might want to have a system where an extension can declare that it 
provides capabilites, and then have another extension require those 
capabilities. That would be a neater solution to the case that there are 
multiple extensions that all provide the same capability.


--
  Heikki Linnakangas
  EnterpriseDB   http://www.enterprisedb.com

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] Satisfy extension dependency by one of multiple extensions

2011-09-23 Thread Yeb Havinga

On 2011-09-23 14:19, Heikki Linnakangas wrote:

On 23.09.2011 14:56, Yeb Havinga wrote:

I have a use case where an extension dependency can be satisfied by one
of five other extensions. Currently I'm unable to express that in the
extension control file, since the elements from 'requires' are currently
searched on exact name match. The attached patch changes this behaviour
for list elements that end with a *, into prefix matching, so that e.g.
table* matches tablefunc.


That's going to quickly extend into even more complex rules, like foo 
OR bar, (foo OR bar) AND (foobar) etc. IIRC the extension control 
file format was modeled after some other package management system 
(.deb ?). You might want to look at the past discussions when the 
extension control file format was decided.


Ech.. 2364 hits on 'extension' in my mailbox. However I found a thread 
'extension dependency checking' that also talks about version numbers 
and the 'provides' capability you mention below.


We might want to have a system where an extension can declare that it 
provides capabilites, and then have another extension require 
those capabilities. That would be a neater solution to the case that 
there are multiple extensions that all provide the same capability.




Yes that would be neater. I can't think of anything else however than to 
add 'extprovides' to pg_extension, fill it with an explicit 'provides' 
from the control file when present, or extname otherwise, and use that 
column to check the 'requires' list on extension creation time.


--
Yeb Havinga
http://www.mgrid.net/
Mastering Medical Data


--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers