# How to rewrite fdb GetKeyValuesReply?

**URL:** https://forums.foundationdb.org/t/how-to-rewrite-fdb-getkeyvaluesreply/4342
**Category:** Development
**Created:** [January 30, 2024, 8:48am UTC](https://forums.foundationdb.org/t/how-to-rewrite-fdb-getkeyvaluesreply/4342 "2024-01-30T08:48:29Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![gripleaf](https://sea1.discourse-cdn.com/foundationdb/user_avatar/forums.foundationdb.org/gripleaf/32/1642_2.png) [@gripleaf](https://forums.foundationdb.org/u/gripleaf)
#### Post date: [January 30, 2024, 8:48am UTC](https://forums.foundationdb.org/t/how-to-rewrite-fdb-getkeyvaluesreply/4342/1 "2024-01-30T08:48:29Z")

</div>

For some reason, I want to rewrite the fdb GetKeyValuesReply before SS send back reply. The code modified in `storageserver.actor.cpp:getKeyValuesQ` with fdb 7.1.44:

```auto
			if (!r.data.empty() && /*some conditions*/) {
				GetKeyValuesReply new_r;
				new_r.arena.dependsOn(r.arena);
				new_r.penalty = r.penalty;
				new_r.more = r.more;
				new_r.version = r.version;
				new_r.cached = r.cached;
				new_r.error = r.error;
				for (int i = 0; i < r.data.size(); i++) {
					if (filterOut(r.data[i].key, r.data[i].value) && (i != 0 && i != r.data.size() -1)) {
                                        	// filter out the data item except first and last item.
                                        	continue;
					}
					
					new_r.data.push_back(new_r.arena, r.data[i]);
				}
				req.reply.send(new_r);
			} else {
				req.reply.send(r);
			}

```

when I compile & run above code, it always cause core dump.

Is there something wrong that I didn’t recognize about arena or send func?

---

<div class="post-metadata">

### Author: ![gripleaf](https://sea1.discourse-cdn.com/foundationdb/user_avatar/forums.foundationdb.org/gripleaf/32/1642_2.png) [@gripleaf](https://forums.foundationdb.org/u/gripleaf)
#### Post date: [January 30, 2024, 9:30am UTC](https://forums.foundationdb.org/t/how-to-rewrite-fdb-getkeyvaluesreply/4342/2 "2024-01-30T09:30:49Z")

</div>

I try another way to build my reply, it seems work. example code like:

```auto
			if (!r.data.empty() && /*some conditions*/) {
				int offset = 0;
				for (int i = 0; i < r.data.size(); i++) {
					if (filterOut(r.data[i].key, r.data[i].value) && (i != 0 && i != r.data.size() -1)) {
						continue;
					}
					r.data[offset] = r.data[i];
					offset++;
				}
				while (r.data.size() > offset) { r.data.pop_back(); }
				req.reply.send(r);
			} else {
				req.reply.send(r);
			}

```

It seems I make some mistakes on arena…

When SS really call send in network level, the `new_r` memory in above code is freed, then SS access invalid memory address and core dump.

---

<div class="post-metadata">

### Author: ![gripleaf](https://sea1.discourse-cdn.com/foundationdb/user_avatar/forums.foundationdb.org/gripleaf/32/1642_2.png) [@gripleaf](https://forums.foundationdb.org/u/gripleaf)
#### Post date: [February 2, 2024, 2:48am UTC](https://forums.foundationdb.org/t/how-to-rewrite-fdb-getkeyvaluesreply/4342/3 "2024-02-02T02:48:11Z")

</div>

Is anyone can help me explain above problem, or provide some documents about arena?
