Thread: double opens

double opens

From
"Hiroshi Inoue"
Date:
Hi all,

There is a TODO item
* Overhaul mdmgr/smgr to fix double unlinking and double opens, cleanup

In Windows-NT,we could see the following error reported by 
yutaka tanida [yutaka@marin.or.jp]. 

> version
> ------------------------------------------------------------
> PostgreSQL 6.5.1 on i686-pc-cygwin, compiled by gcc gcc-2.95
> (1 row)
>
> template1=> create table table1 ( i int,j int);
> CREATE
> template1=> create view view1 as select * from table1;
> CREATE
> template1=> drop view view1;
> DROP
> template1=> create view view1 as select * from table1;
> ERROR:  cannot create view1

"drop view" couldn't unlink the base file of target view because
it is doubly opened and so "create view" coundn't create the view. 

After applying the following patch on trial,"drop view" was able to
unlink the base file and "create view" was able to create the view
again.

I think base files should be closed at the time of cache invalidation.
RelationFlushRelation() invalidates the entry of relation cache but
doesn't close the base file of target relation.
Is there any reason ?

Or why doesn't RelationCacheDelete() close the base file of 
target relation ?

Regards.

Hiroshi Inoue
Inoue@tpf.co.jp

*** utils/cache/relcache.c.orig    Wed May 26 16:05:38 1999
--- utils/cache/relcache.c    Wed Jul 28 13:23:49 1999
***************
*** 1282,1287 ****
--- 1282,1288 ----         oldcxt = MemoryContextSwitchTo((MemoryContext) CacheCxt);
RelationCacheDelete(relation);
+         smgrclose(DEFAULT_SMGR, relation);          FreeTupleDesc(relation->rd_att);
SystemCacheRelationFlushed(RelationGetRelid(relation));



Re: [HACKERS] double opens

From
Bruce Momjian
Date:
[Charset iso-8859-1 unsupported, filtering to ASCII...]
> Hi all,
> 
> There is a TODO item
> * Overhaul mdmgr/smgr to fix double unlinking and double opens, cleanup
> 
> In Windows-NT,we could see the following error reported by 
> yutaka tanida [yutaka@marin.or.jp]. 
> 
> > version
> > ------------------------------------------------------------
> > PostgreSQL 6.5.1 on i686-pc-cygwin, compiled by gcc gcc-2.95
> > (1 row)
> >
> > template1=> create table table1 ( i int,j int);
> > CREATE
> > template1=> create view view1 as select * from table1;
> > CREATE
> > template1=> drop view view1;
> > DROP
> > template1=> create view view1 as select * from table1;
> > ERROR:  cannot create view1
> 
> "drop view" couldn't unlink the base file of target view because
> it is doubly opened and so "create view" coundn't create the view. 
> 
> After applying the following patch on trial,"drop view" was able to
> unlink the base file and "create view" was able to create the view
> again.
> 
> I think base files should be closed at the time of cache invalidation.
> RelationFlushRelation() invalidates the entry of relation cache but
> doesn't close the base file of target relation.
> Is there any reason ?
> 
> Or why doesn't RelationCacheDelete() close the base file of 
> target relation ?
> 
> Regards.
> 
> Hiroshi Inoue
> Inoue@tpf.co.jp
> 
> *** utils/cache/relcache.c.orig    Wed May 26 16:05:38 1999
> --- utils/cache/relcache.c    Wed Jul 28 13:23:49 1999
> ***************
> *** 1282,1287 ****
> --- 1282,1288 ----
>           oldcxt = MemoryContextSwitchTo((MemoryContext) CacheCxt);
>   
>           RelationCacheDelete(relation);
> +         smgrclose(DEFAULT_SMGR, relation);
>   
>           FreeTupleDesc(relation->rd_att);
>           SystemCacheRelationFlushed(RelationGetRelid(relation));
> 
> 
> 

Basically, I thought the close was done already in the drop table code. 
Is it strange to do the close inside the cache?  The cache does the
opens, right?


--  Bruce Momjian                        |  http://www.op.net/~candle maillist@candle.pha.pa.us            |  (610)
853-3000+  If your life is a hard drive,     |  830 Blythe Avenue +  Christ can be your backup.        |  Drexel Hill,
Pennsylvania19026
 


RE: [HACKERS] double opens

From
"Hiroshi Inoue"
Date:
> 
> [Charset iso-8859-1 unsupported, filtering to ASCII...]
> > Hi all,
> > 
> > There is a TODO item
> > * Overhaul mdmgr/smgr to fix double unlinking and double opens, cleanup
> > 
> > In Windows-NT,we could see the following error reported by 
> > yutaka tanida [yutaka@marin.or.jp]. 
> > 
> > > version
> > > ------------------------------------------------------------
> > > PostgreSQL 6.5.1 on i686-pc-cygwin, compiled by gcc gcc-2.95
> > > (1 row)
> > >
> > > template1=> create table table1 ( i int,j int);
> > > CREATE
> > > template1=> create view view1 as select * from table1;
> > > CREATE
> > > template1=> drop view view1;
> > > DROP
> > > template1=> create view view1 as select * from table1;
> > > ERROR:  cannot create view1
> > 
> > "drop view" couldn't unlink the base file of target view because
> > it is doubly opened and so "create view" coundn't create the view. 
> >
[snip]

> > 
> > *** utils/cache/relcache.c.orig    Wed May 26 16:05:38 1999
> > --- utils/cache/relcache.c    Wed Jul 28 13:23:49 1999
> > ***************
> > *** 1282,1287 ****
> > --- 1282,1288 ----
> >           oldcxt = MemoryContextSwitchTo((MemoryContext) CacheCxt);
> >   
> >           RelationCacheDelete(relation);
> > +         smgrclose(DEFAULT_SMGR, relation);
> >   
> >           FreeTupleDesc(relation->rd_att);
> >           SystemCacheRelationFlushed(RelationGetRelid(relation));
> > 
> > 
> > 
> 
> Basically, I thought the close was done already in the drop table code. 
> Is it strange to do the close inside the cache?  The cache does the
> opens, right?
>

No,relcache stuff doesn't do the opens.

First,my patch is not only for "drop view"  case.
It's for cases such that  A backend registers an information to invalidate a relcache   entry and another backend
removesthe relcache entry trig-  gered by the information.
 

"drop view" plays both of the part alone and doubly opens
as follows.

RemoveView() RemoveRewriteRule()   prs2_deleteFromRelation()      heap_open(relid of view) ----  opens a new file
descriptor            for the base file of the view        setRelhasrulesInRelations()          heap_replace(tuple of
"pg_class")---- registers an informat-                ion to invalidate the view's                 relcache entry.
heap_close()---- doesn't close the file descriptor CommandCounterIncrement()      .................
RelationFlushRelation()--- removes the relcache entry                   of the view heap_destroy_with_catalog()
heap_openr(viewName)--- opens another file descriptor                for the same view because
heap_openr()couldn't find the                relcache entry
 

Regards.

Hiroshi Inoue
Inoue@tpf.co.jp



Re: [HACKERS] double opens

From
Bruce Momjian
Date:
Tom, can you comment on this patch.  Seems you have made changes in this
area.  Thanks.


[Charset iso-8859-1 unsupported, filtering to ASCII...]
> Hi all,
> 
> There is a TODO item
> * Overhaul mdmgr/smgr to fix double unlinking and double opens, cleanup
> 
> In Windows-NT,we could see the following error reported by 
> yutaka tanida [yutaka@marin.or.jp]. 
> 
> > version
> > ------------------------------------------------------------
> > PostgreSQL 6.5.1 on i686-pc-cygwin, compiled by gcc gcc-2.95
> > (1 row)
> >
> > template1=> create table table1 ( i int,j int);
> > CREATE
> > template1=> create view view1 as select * from table1;
> > CREATE
> > template1=> drop view view1;
> > DROP
> > template1=> create view view1 as select * from table1;
> > ERROR:  cannot create view1
> 
> "drop view" couldn't unlink the base file of target view because
> it is doubly opened and so "create view" coundn't create the view. 
> 
> After applying the following patch on trial,"drop view" was able to
> unlink the base file and "create view" was able to create the view
> again.
> 
> I think base files should be closed at the time of cache invalidation.
> RelationFlushRelation() invalidates the entry of relation cache but
> doesn't close the base file of target relation.
> Is there any reason ?
> 
> Or why doesn't RelationCacheDelete() close the base file of 
> target relation ?
> 
> Regards.
> 
> Hiroshi Inoue
> Inoue@tpf.co.jp
> 
> *** utils/cache/relcache.c.orig    Wed May 26 16:05:38 1999
> --- utils/cache/relcache.c    Wed Jul 28 13:23:49 1999
> ***************
> *** 1282,1287 ****
> --- 1282,1288 ----
>           oldcxt = MemoryContextSwitchTo((MemoryContext) CacheCxt);
>   
>           RelationCacheDelete(relation);
> +         smgrclose(DEFAULT_SMGR, relation);
>   
>           FreeTupleDesc(relation->rd_att);
>           SystemCacheRelationFlushed(RelationGetRelid(relation));
> 
> 
> 


--  Bruce Momjian                        |  http://www.op.net/~candle maillist@candle.pha.pa.us            |  (610)
853-3000+  If your life is a hard drive,     |  830 Blythe Avenue +  Christ can be your backup.        |  Drexel Hill,
Pennsylvania19026
 


Re: [HACKERS] double opens

From
Tom Lane
Date:
Bruce Momjian <maillist@candle.pha.pa.us> writes:
> Tom, can you comment on this patch.  Seems you have made changes in this
> area.  Thanks.

This change is in place in current sources --- it's a few lines away from
where Hiroshi suggested, but I don't think that makes any difference...

>> *** utils/cache/relcache.c.orig    Wed May 26 16:05:38 1999
>> --- utils/cache/relcache.c    Wed Jul 28 13:23:49 1999
>> ***************
>> *** 1282,1287 ****
>> --- 1282,1288 ----
>> oldcxt = MemoryContextSwitchTo((MemoryContext) CacheCxt);
>> 
>> RelationCacheDelete(relation);
>> +         smgrclose(DEFAULT_SMGR, relation);
>> 
>> FreeTupleDesc(relation->rd_att);
>> SystemCacheRelationFlushed(RelationGetRelid(relation));
>> 
>> 
>> 
        regards, tom lane


Re: [HACKERS] double opens

From
Bruce Momjian
Date:
> Bruce Momjian <maillist@candle.pha.pa.us> writes:
> > Tom, can you comment on this patch.  Seems you have made changes in this
> > area.  Thanks.
> 
> This change is in place in current sources --- it's a few lines away from
> where Hiroshi suggested, but I don't think that makes any difference...

Sorry, I missed it the first time.  I see it now. Thanks.



> 
> >> *** utils/cache/relcache.c.orig    Wed May 26 16:05:38 1999
> >> --- utils/cache/relcache.c    Wed Jul 28 13:23:49 1999
> >> ***************
> >> *** 1282,1287 ****
> >> --- 1282,1288 ----
> >> oldcxt = MemoryContextSwitchTo((MemoryContext) CacheCxt);
> >> 
> >> RelationCacheDelete(relation);
> >> +         smgrclose(DEFAULT_SMGR, relation);
> >> 
> >> FreeTupleDesc(relation->rd_att);
> >> SystemCacheRelationFlushed(RelationGetRelid(relation));
> >> 
> >> 
> >> 
> 
>             regards, tom lane
> 


--  Bruce Momjian                        |  http://www.op.net/~candle maillist@candle.pha.pa.us            |  (610)
853-3000+  If your life is a hard drive,     |  830 Blythe Avenue +  Christ can be your backup.        |  Drexel Hill,
Pennsylvania19026