应用程序引擎数据存储:逐步更新地形高度图的模型 [英] app engine datastore: model for progressively updated terrain height map

查看:103
本文介绍了应用程序引擎数据存储:逐步更新地形高度图的模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

用户提交与地形图关联的矩形轴对齐区域。
$ b

  class Region(db.Model):
terrain_map = reference到TerrainMap
top_left_x =整数
top_left_y =整数
bottom_right_x =整数
bottom_right_y =整数

我想维护一个地形高度图,它会随着新的矩形区域的添加或删除而逐步更新。

 类TerrainMap(db.Model):
terrain_height = blob

以下是两张重叠地区的地图外观的图片: http://pastebin.com/4yzXSFC5



所以我认为我可以通过添加RegionUpdate模型来实现这一点,Region模型是在创建或删除Region实体时创建的,并且还可以排队通过查询RegionUpdate.applied = False

  class RegionUpdat e(db.Model):
terrain_map =对TerrainMap的引用
top_left_x =整数
top_left_y =整数
bottom_right_x =整数
bottom_right_y =整数
操作=字符串,增加或减少
applied = False / True

是否似乎所有RegionUpdates和Region实体都必须与它们的TerrainMap位于同一个实体组下:RegionUpdates只有在创建或删除Region实体时才能创建,因此必须以事务方式完成; TerrainMap.terrain_height在任务中更新,所以这必须是一个幂等操作 - 我只能想到通过事务性地抓取一批RegionUpdate实体,然后将它们应用到TerrainMap。



这使得我的实体组大大超过了单个用户的数据量或更小的数据量的经验法则大小。



我是忽略了一些更好的方法来模拟这个? 解决方案

正如我在Reddit问题中所建议的,我认为 Brett的数据管道协议有你需要建立这个的所有信息。基本方法是:每次插入或更新区域时,在同一个实体组中添加一个标记实体。然后,在该任务中,使用新数据更新相应的TerrainMap,并将Marker实体留为其子项,表示您已应用该更新。另一方面,您还没有指定每个TerrainMap预计会有多少个区域,或者它们将被更新的频率。如果对单个地形图的更新率不是很高,那么可以将所有区域简单地存储为它们所应用的TerrainMap的子实体,并且可以在单个事务中同步更新地图或在任务队列中更新地图,更简单。


Users submit rectangular axis-aligned regions associated with "terrain maps". At any time users can delete regions they have created.

class Region(db.Model):
  terrain_map = reference to TerrainMap
  top_left_x = integer
  top_left_y = integer
  bottom_right_x = integer
  bottom_right_y = integer

I want to maintain a "terrain height map", which progressively updates as new rectangular regions are added or deleted.

class TerrainMap(db.Model):
  terrain_height = blob

Here's a "picture" of what the map could look like with two overlapping regions: http://pastebin.com/4yzXSFC5

So i thought i could do this by adding a RegionUpdate model, created when Region entity is either created or deleted, and also enqueuing a Task which would churn through a query for "RegionUpdate.applied = False"

class RegionUpdate(db.Model):
  terrain_map = reference to TerrainMap
  top_left_x = integer
  top_left_y = integer
  bottom_right_x = integer
  bottom_right_y = integer
  operation = string, either "increase" or "decrease"
  applied = False/True

The problem is it seems all RegionUpdates and Region entities have to be under the same entity group as their TerrainMap: RegionUpdates must only get created when Region entities are created or deleted, so this must be done transactionally; TerrainMap.terrain_height is updated in a Task, so this must be an idempotent operation - i can only think of doing this by transactionally grabbing a batch of RegionUpdate entities, then applying them to the TerrainMap.

That makes my entity group much larger than the "rule of thumb" size of about "a single user's worth of data or smaller".

Am i overlooking some better way to model this?

解决方案

As I suggested in the Reddit question, I think that Brett's data pipelines talk has all the information you need to build this. The basic approach is this: Every time you insert or update a Region, add a 'marker' entity in the same entity group. Then, in that task, update the corresponding TerrainMap with the new data, and leave a Marker entity as a child of that, too, indicating that you've applied that update. See the talk for full details.

On the other hand, you haven't specified how many Regions you expect per TerrainMap, or how frequently they'll be updated. If the update rate to a single terrain map isn't huge, you could simply store all the regions as child entities of the TerrainMap to which they apply, and update the map synchronously or on the task queue in a single transaction, which is much simpler.

这篇关于应用程序引擎数据存储:逐步更新地形高度图的模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆