Uploaded image for project: 'Geode'
  1. Geode
  2. GEODE-10160

SizeableByteArrayList does not update the sizeInBytes for some non-overriden methods

    XMLWordPrintableJSON

Details

    Description

      Some List methods aren't overriden in SizeableByteArrayList which means that the memoryOverhead doesn't get updated. add(int index, byte[] element), clear(), and set(int index, byte[] newElement) all need to update the size and don't.

      This can be accomplished by adding overrides to SizeableByteArrayList:

        @Override
        public byte[] set(int index, byte[] newElement) {
          byte[] replacedElement = super.set(index, newElement);
          memberOverhead -= calculateByteArrayOverhead(replacedElement);
          memberOverhead += calculateByteArrayOverhead(newElement);
          return replacedElement;
        }
      
        @Override
        public void add(int index, byte[] element) {
          memberOverhead += calculateByteArrayOverhead(element);
          super.add(index, element);
        }
      

      The test for set could look something like:

        @Test
        public void sizeInBytesGetsUpdatedAccurately_whenDoingSets() {
          SizeableByteArrayList list = new SizeableByteArrayList();
          byte[] element = "element".getBytes(StandardCharsets.UTF_8);
          list.addFirst(element);
          long initialSize = list.getSizeInBytes();
          assertThat(initialSize).isEqualTo(sizer.sizeof(list));
          list.set(0, "some really big new element name".getBytes(StandardCharsets.UTF_8));
          assertThat(list.getSizeInBytes()).isEqualTo(sizer.sizeof(list));
          list.set(0, element);
          assertThat(list.getSizeInBytes()).isEqualTo(initialSize);
        }
      

      We need more tests than just this one. add(int, byte[]) needs to be tested as well. Any method on SizeableByteArrayList that modify the data should have a test that the memoryOverhead gets updated correctly.

      Clear itself isn't a problem - just set the memberOverhead to 0 - but the issue is that for the version of LTRIM in PR#7403, we clear a sublist of SizeableByteArrayList. This means that the overridden clear method does not get called and the LinkedList implementation of clear does not call any other methods that we can override. There needs to be some new approach to LTRIM that doesn't use sublists.

      Attachments

        Issue Links

          Activity

            People

              ssienkowski Steve Sienkowski
              balesh2 Hale Bales
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: