![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
THE SCENARIO: I've got a database that uses fixed size keys (16 bytes) and variable size values. The database is configured for BTREE and duplicates. To extract the duplicates for a given key I use a Dbc and loop until I've grabbed all the duplicates. THE PROBLEM: Whenever I create a Dbt object (as the key) and set the DB_DBT_USERMEM flag, after the initial Dbc.get, subsequent gets throws a DbException saying: quote-snippet Dbt not large enough for available data at com.sleepycat.db.db_javaJNI.Dbc_get__SWIG_0(Native Method) at com.sleepycat.db.Dbc.get(Dbc.java:791) .... /quote-snippet I'm including the code of the method that causes the problem code public Collection<String> get( long k ) throws IOException { Collection<String> c = null; Utf8StringDbt data = new Utf8StringDbt(); // Converts k to a Dbt by prefixing it w/ its parent key Dbt key = convert( k ); key.setFlags( Db.DB_DBT_USERMEM ); try { Dbc cursor = bdDb.getBerkleyDb( dbName ).cursor( null, 0 ); try { if( 0 == cursor.get( key, data, Db.DB_SET ) ) { c = new LinkedList<String>(); do c.add( data.toString() ); while( 0 == cursor.get( key, data, Db.DB_NEXT_DUP ) ); } } finally { cursor.close(); } } catch( DbException e ) { throw new RuntimeException( e ); } return c; } /code If I remove the call to setFlag the error goes away. I know the keys are only 16 bytes wide. I've even written debugging code where the key used in the [while] loop is a freshly created Dbt. After each iteration of the loop I print [to stderr] the offset and size of the Dbt. It's always 0 and 16 respectively. In a moment of utter frustration I modified the convert method to create a Dbt w/ a size of 1024 bytes, more than enough for even the data, but I still get the Exception complaining about not big enough. Why won't Berkeley DB accept my 'static' key? |
![]() |
| Thread Tools | |
| Display Modes | |
| |