@@ -1928,68 +1928,37 @@ private BigRow createRandomRow(long[] intValues, double[] doubleValues,
19281928 new MiddleStruct (inner , inner2 ), list (), map (inner ,inner2 ));
19291929 }
19301930
1931- private static class MyMemoryManager implements MemoryManager {
1932- final long totalSpace ;
1933- double rate ;
1934- Path path = null ;
1935- long lastAllocation = 0 ;
1936- int rows = 0 ;
1937- MemoryManager .Callback callback ;
1938-
1939- MyMemoryManager (Configuration conf , long totalSpace , double rate ) {
1940- this .totalSpace = totalSpace ;
1941- this .rate = rate ;
1942- }
1943-
1944- @ Override
1945- public void addWriter (Path path , long requestedAllocation ,
1946- MemoryManager .Callback callback ) {
1947- this .path = path ;
1948- this .lastAllocation = requestedAllocation ;
1949- this .callback = callback ;
1950- }
1951-
1952- @ Override
1953- public synchronized void removeWriter (Path path ) {
1954- this .path = null ;
1955- this .lastAllocation = 0 ;
1956- }
1957-
1958- @ Override
1959- public void addedRow (int count ) throws IOException {
1960- rows += count ;
1961- if (rows >= 100 ) {
1962- callback .checkMemory (rate );
1963- rows = 0 ;
1964- }
1965- }
1966- }
1967-
19681931 @ Test
19691932 public void testMemoryManagementV11 () throws Exception {
1933+ OrcConf .ROWS_BETWEEN_CHECKS .setLong (conf , 100 );
1934+ final long poolSize = 50_000 ;
19701935 ObjectInspector inspector ;
19711936 synchronized (TestOrcFile .class ) {
19721937 inspector = ObjectInspectorFactory .getReflectionObjectInspector
19731938 (InnerStruct .class ,
19741939 ObjectInspectorFactory .ObjectInspectorOptions .JAVA );
19751940 }
1976- MyMemoryManager memory = new MyMemoryManager (conf , 10000 , 0.1 );
1941+ MemoryManager memoryManager = new MemoryManagerImpl (poolSize );
1942+ // set up 10 files that all request the full size.
1943+ MemoryManager .Callback ignore = newScale -> false ;
1944+ for (int f =0 ; f < 9 ; ++f ) {
1945+ memoryManager .addWriter (new Path ("file-" + f ), poolSize , ignore );
1946+ }
19771947 Writer writer = OrcFile .createWriter (testFilePath ,
19781948 OrcFile .writerOptions (conf )
19791949 .inspector (inspector )
19801950 .compress (CompressionKind .NONE )
19811951 .stripeSize (50000 )
19821952 .bufferSize (100 )
19831953 .rowIndexStride (0 )
1984- .memory (memory )
1954+ .memory (memoryManager )
19851955 .batchSize (100 )
19861956 .version (OrcFile .Version .V_0_11 ));
1987- assertEquals (testFilePath , memory . path );
1957+ assertEquals (0.1 , (( MemoryManagerImpl ) memoryManager ). getAllocationScale () );
19881958 for (int i =0 ; i < 2500 ; ++i ) {
19891959 writer .addRow (new InnerStruct (i *300 , Integer .toHexString (10 *i )));
19901960 }
19911961 writer .close ();
1992- assertEquals (null , memory .path );
19931962 Reader reader = OrcFile .createReader (testFilePath ,
19941963 OrcFile .readerOptions (conf ).filesystem (fs ));
19951964 int i = 0 ;
@@ -2004,29 +1973,35 @@ public void testMemoryManagementV11() throws Exception {
20041973
20051974 @ Test
20061975 public void testMemoryManagementV12 () throws Exception {
1976+ OrcConf .ROWS_BETWEEN_CHECKS .setLong (conf , 100 );
1977+ final long poolSize = 50_000 ;
20071978 ObjectInspector inspector ;
20081979 synchronized (TestOrcFile .class ) {
20091980 inspector = ObjectInspectorFactory .getReflectionObjectInspector
20101981 (InnerStruct .class ,
20111982 ObjectInspectorFactory .ObjectInspectorOptions .JAVA );
20121983 }
2013- MyMemoryManager memory = new MyMemoryManager (conf , 10000 , 0.1 );
1984+ MemoryManager memoryManager = new MemoryManagerImpl (poolSize );
1985+ // set up 10 files that all request the full size.
1986+ MemoryManager .Callback ignore = newScale -> false ;
1987+ for (int f =0 ; f < 9 ; ++f ) {
1988+ memoryManager .addWriter (new Path ("file-" + f ), poolSize , ignore );
1989+ }
20141990 Writer writer = OrcFile .createWriter (testFilePath ,
2015- OrcFile .writerOptions (conf )
2016- .inspector (inspector )
2017- .compress (CompressionKind .NONE )
2018- .stripeSize (50000 )
2019- .bufferSize (100 )
2020- .rowIndexStride (0 )
2021- .memory (memory )
2022- .batchSize (100 )
2023- .version (OrcFile .Version .V_0_12 ));
2024- assertEquals (testFilePath , memory . path );
1991+ OrcFile .writerOptions (conf )
1992+ .inspector (inspector )
1993+ .compress (CompressionKind .NONE )
1994+ .stripeSize (50000 )
1995+ .bufferSize (100 )
1996+ .rowIndexStride (0 )
1997+ .memory (memoryManager )
1998+ .batchSize (100 )
1999+ .version (OrcFile .Version .V_0_12 ));
2000+ assertEquals (0.1 , (( MemoryManagerImpl ) memoryManager ). getAllocationScale () );
20252001 for (int i =0 ; i < 2500 ; ++i ) {
20262002 writer .addRow (new InnerStruct (i *300 , Integer .toHexString (10 *i )));
20272003 }
20282004 writer .close ();
2029- assertEquals (null , memory .path );
20302005 Reader reader = OrcFile .createReader (testFilePath ,
20312006 OrcFile .readerOptions (conf ).filesystem (fs ));
20322007 int i = 0 ;
0 commit comments